From 36576f36d0b018c24c5590866a5569f80a767af7 Mon Sep 17 00:00:00 2001 From: Yan Wong Date: Thu, 2 Mar 2023 15:22:21 +0000 Subject: [PATCH] str(null_schema) returns "Null_schema" not None --- python/tests/test_tables.py | 13 ++++++------- python/tskit/metadata.py | 7 +++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/python/tests/test_tables.py b/python/tests/test_tables.py index 919f2309ef..7e56e516ff 100644 --- a/python/tests/test_tables.py +++ b/python/tests/test_tables.py @@ -1,6 +1,6 @@ # MIT License # -# Copyright (c) 2018-2022 Tskit Developers +# Copyright (c) 2018-2023 Tskit Developers # Copyright (c) 2017 University of Oxford # # Permission is hereby granted, free of charge, to any person obtaining a copy @@ -1321,9 +1321,8 @@ def test_metadata_schema(self, table_5row): table2.metadata_schema = tskit.MetadataSchema({"codec": "json"}) with pytest.raises( AssertionError, - match=f"{type(table_5row).__name__} metadata schemas differ: self=None " - f"other=OrderedDict([('codec', " - "'json')])", + match=f"{type(table_5row).__name__} metadata schemas differ: " + "self=Null_schema other=OrderedDict([('codec', 'json')])", ): table_5row.assert_equals(table2) table_5row.assert_equals(table2, ignore_metadata=True) @@ -3990,7 +3989,7 @@ def test_metadata_schema(self, t1, t2): AssertionError, match=re.escape( "Metadata schemas differ: self=OrderedDict([('codec', 'json')]) " - "other=None" + "other=Null_schema" ), ): t1.assert_equals(t2) @@ -4039,7 +4038,7 @@ def test_ignore_metadata(self, t1, t2, table_name): AssertionError, match=re.escape( f"{type(table).__name__} metadata schemas differ: " - f"self=OrderedDict([('codec', 'json')]) other=None" + f"self=OrderedDict([('codec', 'json')]) other=Null_schema" ), ): t1.assert_equals(t2) @@ -4100,7 +4099,7 @@ def test_ignore_reference_sequence(self, t1, t2): AssertionError, match=re.escape( "Metadata schemas differ: " - "self=OrderedDict([('codec', 'json')]) other=None" + "self=OrderedDict([('codec', 'json')]) other=Null_schema" ), ): t1.assert_equals(t2) diff --git a/python/tskit/metadata.py b/python/tskit/metadata.py index b4c978d51c..78e6b97269 100644 --- a/python/tskit/metadata.py +++ b/python/tskit/metadata.py @@ -1,6 +1,6 @@ # MIT License # -# Copyright (c) 2020-2022 Tskit Developers +# Copyright (c) 2020-2023 Tskit Developers # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -654,7 +654,10 @@ def __repr__(self) -> str: return self._string def __str__(self) -> str: - return pprint.pformat(self._schema) + if self._schema is None: + return "Null_schema" + else: + return pprint.pformat(self._schema) def __eq__(self, other) -> bool: return self._string == other._string