From 544052502274148d2dd4d932ca4dd12f82815b1d Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 17 Dec 2020 09:10:39 +0000 Subject: [PATCH 01/18] test and fix underscore methods --- spinn_utilities/default_ordered_dict.py | 4 ++-- unittests/test_default_ordered_dict.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/spinn_utilities/default_ordered_dict.py b/spinn_utilities/default_ordered_dict.py index 5c82d900..256a3370 100644 --- a/spinn_utilities/default_ordered_dict.py +++ b/spinn_utilities/default_ordered_dict.py @@ -47,7 +47,7 @@ def __reduce__(self): args = tuple() else: args = self.default_factory, - return type(self), args, None, None, self.items() + return type(self), args, None, None, iter(self.items()) def copy(self): return self.__copy__() @@ -58,7 +58,7 @@ def __copy__(self): def __deepcopy__(self, memo): import copy return type(self)(self.default_factory, - copy.deepcopy(self.items())) + copy.deepcopy(iter(self.items()))) def __repr__(self): return 'OrderedDefaultDict(%s, %s)' % ( diff --git a/unittests/test_default_ordered_dict.py b/unittests/test_default_ordered_dict.py index 35eef51b..c81b823d 100644 --- a/unittests/test_default_ordered_dict.py +++ b/unittests/test_default_ordered_dict.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import copy +import pickle import pytest from spinn_utilities.default_ordered_dict import DefaultOrderedDict from spinn_utilities.ordered_set import OrderedSet @@ -53,3 +55,24 @@ def test_keys_in_order(): c = o["c"] assert a == b == c assert tuple(o) == ("a", "b", "c") + +def test_callable(): + try: + DefaultOrderedDict("Not callable") + assert False + except TypeError: + pass + +def test_special_methods(): + o = DefaultOrderedDict(list) + o["gamma"].append("bacon") + # test _-reduce + pickle.dumps(o) + # test copy + o2 = o.copy() + assert o2["gamma"] == ["bacon"] + o3 = copy.deepcopy(o) + assert o3["gamma"] == ["bacon"] + a = repr(o) + b = repr(o3) + assert a == b From ff5fa2efcc56f3336381ab13a3da6ce56e271c3a Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 17 Dec 2020 11:53:20 +0000 Subject: [PATCH 02/18] test IndexIsValue --- unittests/test_index_is_value.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 unittests/test_index_is_value.py diff --git a/unittests/test_index_is_value.py b/unittests/test_index_is_value.py new file mode 100644 index 00000000..dada43d5 --- /dev/null +++ b/unittests/test_index_is_value.py @@ -0,0 +1,22 @@ +# Copyright (c) 2017-2018 The University of Manchester +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from spinn_utilities.index_is_value import IndexIsValue + + +def test_index_is_value(): + a = IndexIsValue() + assert a[10] == 10 + assert len(a) > 1000 From b45cf23dfbb02c635087bcf45441d288677b62d0 Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 17 Dec 2020 13:11:39 +0000 Subject: [PATCH 03/18] test different configs --- unittests/test_log.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/unittests/test_log.py b/unittests/test_log.py index d4e7b88f..753b14d7 100644 --- a/unittests/test_log.py +++ b/unittests/test_log.py @@ -14,7 +14,9 @@ # along with this program. If not, see . import logging -from spinn_utilities.log import FormatAdapter, LogLevelTooHighException +from spinn_utilities.log import ( + ConfiguredFilter, ConfiguredFormatter, FormatAdapter, + LogLevelTooHighException) class MockLog(object): @@ -95,3 +97,32 @@ class Exn(Exception): assert "exc_info" in log.last_kwargs assert log.last_level == logging.ERROR assert len(logger._repeat_log()) == 1 + + +class MockConfig1(): + + def get(self, section, option): + return "debug" + + def has_section(self, section): + return False + + +def test_weird_config1(): + ConfiguredFormatter(MockConfig1()) + ConfiguredFilter(MockConfig1()) + +class MockConfig2(): + + def get(self, section, option): + return "foo,bar" + + def has_section(self, section): + return True + + def has_option(self, section, option): + return option == 'warning' + +def test_weird_config2(): + ConfiguredFormatter(MockConfig2()) + ConfiguredFilter(MockConfig2()) From 3bce630d430509c4eb4476d00de6cd81efb02d29 Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 17 Dec 2020 13:13:53 +0000 Subject: [PATCH 04/18] test log same error twice --- unittests/test_logger_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/unittests/test_logger_utils.py b/unittests/test_logger_utils.py index d948eb33..c6c06e54 100644 --- a/unittests/test_logger_utils.py +++ b/unittests/test_logger_utils.py @@ -63,6 +63,7 @@ def test_error(self): logger_utils.error_once(logger, "a log Error") logger_utils.warn_once(logger, "another log error") logger_utils.warn_once(logger, "a log warning") + logger_utils.error_once(logger, "a log Error") log_checker.assert_logs_contains_once( "ERROR", lc.records, "a log Error") log_checker.assert_logs_error_not_contains( From 5faba2661e859240cb14e2ff486240c973e12ebb Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 17 Dec 2020 13:43:05 +0000 Subject: [PATCH 05/18] test pop last = False --- unittests/test_ordered_set.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/unittests/test_ordered_set.py b/unittests/test_ordered_set.py index 96c1eba0..7685dc3b 100644 --- a/unittests/test_ordered_set.py +++ b/unittests/test_ordered_set.py @@ -139,4 +139,17 @@ def test_peek(): o.add(2) o.add(3) p1 = o.peek() + p2 = o.pop() assert p1 == 3 + assert p1 == p2 + p3 = o.peek(last=False) + assert p3 == 1 + + +def test_reverse(): + o = OrderedSet() + o.add(1) + o.add(2) + o.add(3) + a = list(reversed(o)) + assert a == [3, 2, 1] From 03feb43ee7d85d78044ce7229b4bbf99acb8a0a1 Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 17 Dec 2020 15:17:53 +0000 Subject: [PATCH 06/18] more config types --- unittests/test_conf_loader.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/unittests/test_conf_loader.py b/unittests/test_conf_loader.py index e2ba6a5c..c17ab546 100644 --- a/unittests/test_conf_loader.py +++ b/unittests/test_conf_loader.py @@ -116,6 +116,28 @@ def test_new_section_validation(tmpdir, default_config): conf_loader.load_config(CFGFILE, [CFGPATH], validation_cfg="blank.cfg") +def test_types(tmpdir, default_config): + with tmpdir.as_cwd(): + f = tmpdir.join(CFGFILE) + default_config = ( + default_config + + "[machine]\nmachineName=foo\nVersion=5\nsize=4.6\nb1=True\n" + "b2=true\nb3=False\nb4=False\nOops=None\n") + f.write(default_config) + config = conf_loader.load_config( + CFGFILE, [CFGPATH], validation_cfg="blank.cfg") + a = config.get_int("machine", "version") + assert config.get_int("machine", "version") == 5 + assert config.get_int("machine", "oops") == None + assert config.get_float("machine","size") == 4.6 + assert config.get_float("machine","oops") == None + assert config.get_bool("machine", "b1") + assert config.get_bool("machine", "b2") + assert not config.get_bool("machine", "b3") + assert not config.get_bool("machine", "b4") + assert config.get_bool("machine","oops") == None + + def test_dead_section(tmpdir, default_config): with tmpdir.as_cwd(): f = tmpdir.join(CFGFILE) From 7312c22734cb9ebd702f1476c69a8869dd4c28da Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 17 Dec 2020 15:18:14 +0000 Subject: [PATCH 07/18] test pop last = False --- spinn_utilities/ordered_set.py | 2 +- unittests/test_ordered_set.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spinn_utilities/ordered_set.py b/spinn_utilities/ordered_set.py index 3699190e..6daaccdf 100644 --- a/spinn_utilities/ordered_set.py +++ b/spinn_utilities/ordered_set.py @@ -56,7 +56,7 @@ def peek(self, last=True): if last: return next(reversed(self)) else: - return next(self) + return next(iter(self)) def __len__(self): return len(self._map) diff --git a/unittests/test_ordered_set.py b/unittests/test_ordered_set.py index 7685dc3b..1e77f132 100644 --- a/unittests/test_ordered_set.py +++ b/unittests/test_ordered_set.py @@ -144,6 +144,8 @@ def test_peek(): assert p1 == p2 p3 = o.peek(last=False) assert p3 == 1 + p4 = o.pop(last=False) + assert p4 == p3 def test_reverse(): From aebaeaf364f1002f9c6b4e1c9f91fca6cb3a8881 Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 17 Dec 2020 16:35:03 +0000 Subject: [PATCH 08/18] more file convertor tests --- unittests/make_tools/mock_src/weird,file.c | 7 +++++ unittests/make_tools/test_file_convert.py | 35 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/unittests/make_tools/mock_src/weird,file.c b/unittests/make_tools/mock_src/weird,file.c index 3361aaef..01fd1ed4 100644 --- a/unittests/make_tools/mock_src/weird,file.c +++ b/unittests/make_tools/mock_src/weird,file.c @@ -30,6 +30,10 @@ static String woops = "log_info("; log_info("test -three %f", -3.0f); + log_info("test double %F", -3.0d); + + log_info("test slash // %f", 3/2); + log_info("this is ok"); //log_info("this is just a comment"); @@ -99,6 +103,9 @@ static String woops = "log_info("; ds_regions->version >> VERSION_SHIFT, ds_regions->version & VERSION_MASK); + log_inf("blah", + ")", + "more"); /* comment */ log_info("comment before"); fluff fluff diff --git a/unittests/make_tools/test_file_convert.py b/unittests/make_tools/test_file_convert.py index 744c9a63..9288e425 100644 --- a/unittests/make_tools/test_file_convert.py +++ b/unittests/make_tools/test_file_convert.py @@ -60,3 +60,38 @@ def test_convert(self): assert("then a backslash comment on a middle line" in data) assert("then a standard comment on a middle line" in data) assert("comment before" in data) + + def test_exceptions(self): + file_name = "weird,file.c" + src = os.path.join("mock_src", file_name) + dest = os.path.join("modified_src", file_name) + dict = dest + "dict" + convertor = FileConverter(src, dest, dict) + try: + convertor.split_by_comma_plus(None, 12) + assert False + except Exception as ex1: + assert "Unexpected line" in str(ex1) + try: + convertor._short_log(12) + assert False + except Exception as ex2: + assert "Unexpected line" in str(ex2) + try: + convertor._log_full = '"test %f", -3.0f, 12);' + convertor._short_log(12) + assert False + except Exception as ex2: + assert "Too many" in str(ex2) + try: + convertor._log_full = '"test %f %i", -3.0f);' + convertor._short_log(12) + assert False + except Exception as ex2: + assert "Too few" in str(ex2) + try: + convertor._log_full = '"test %1", -3.0f);' + convertor._short_log(12) + assert False + except Exception as ex2: + assert "Unexpected formatString" in str(ex2) From 36ab252223501e572c4db905739bd4e74a22767f Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 17 Dec 2020 16:45:27 +0000 Subject: [PATCH 09/18] fixed test --- unittests/test_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittests/test_log.py b/unittests/test_log.py index 753b14d7..80eef663 100644 --- a/unittests/test_log.py +++ b/unittests/test_log.py @@ -115,7 +115,7 @@ def test_weird_config1(): class MockConfig2(): def get(self, section, option): - return "foo,bar" + return "critical" def has_section(self, section): return True From c45858d9de2d15a439d2459c03ec3e146405369e Mon Sep 17 00:00:00 2001 From: christian-B Date: Thu, 17 Dec 2020 16:53:03 +0000 Subject: [PATCH 10/18] more test replacer --- unittests/make_tools/test.dict | 5 +++++ unittests/make_tools/test_replacer.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/unittests/make_tools/test.dict b/unittests/make_tools/test.dict index 629456f9..64387737 100644 --- a/unittests/make_tools/test.dict +++ b/unittests/make_tools/test.dict @@ -8,6 +8,9 @@ Id,Preface,Original 1006,[INFO] (weird;file.c: 25): ,Test %u for alan); so there! 1007,[INFO] (weird;file.c: 29): ,\t back off = %u, time between spikes %u 1008,[DEBUG] (weird;file.c: 33): ,the neuron %d has been determined to not spike +A weird lone got in +Another, weird, line, got, in +And one, with, three parts 1009,[WARNING] (weird;file.c: 37): ,Inside a loop 1010,[INFO] (weird;file.c: 39): ,then a space 1011,[INFO] (weird;file.c: 42): ,then a newline simple @@ -20,3 +23,5 @@ Id,Preface,Original 1018,[DEBUG] (bit_field.c: 71): ,%c 1019,[DEBUG] (bit_field.c: 75): ,\n 1020,[DEBUG] (bit_field.c: 111): ,%08x\n +1021,[INFO] (weird;file.c: 32):, a float %f +1022,[INFO] (weird;file.c: 34):, a double %F diff --git a/unittests/make_tools/test_replacer.py b/unittests/make_tools/test_replacer.py index 4e0ae8df..dc5e7f51 100644 --- a/unittests/make_tools/test_replacer.py +++ b/unittests/make_tools/test_replacer.py @@ -45,6 +45,25 @@ def test_tab(self): " spikes 20" assert (message == new) + def test_float(self): + replacer = Replacer(os.path.join(PATH, "test")) + new = replacer.replace("1021" + TOKEN + "3f800000") + message = "[INFO] (weird;file.c: 32): a float 1.0" + assert (message == new) + + def test_double(self): + replacer = Replacer(os.path.join(PATH, "test")) + new = replacer.replace("1022" + TOKEN + "40379999" + TOKEN + "9999999a") + message = "[INFO] (weird;file.c: 34): a double 23.6" + assert (message == new) + + def test_bad(self): + replacer = Replacer(os.path.join(PATH, "test")) + new = replacer.replace("1007" + TOKEN + "10") + # An exception so just output the input + message = "1007" + TOKEN + "10" + assert (message == new) + def near_equals(self, a, b): diff = a - b if diff == 0: From 51e703d2d93af7ade074a07249218d0c66aad87f Mon Sep 17 00:00:00 2001 From: christian-B Date: Fri, 18 Dec 2020 06:54:17 +0000 Subject: [PATCH 11/18] simplify --- spinn_utilities/make_tools/file_converter.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/spinn_utilities/make_tools/file_converter.py b/spinn_utilities/make_tools/file_converter.py index bc65e03a..3d0e107f 100644 --- a/spinn_utilities/make_tools/file_converter.py +++ b/spinn_utilities/make_tools/file_converter.py @@ -396,16 +396,13 @@ def _short_log(self, line_num): front += TOKEN if match.endswith("f"): front += "%x" - elif match.endswith("F"): - front += "%x" + TOKEN + "%x" - else: - front += match - if match.endswith("f"): back += ", float_to_int({})".format(parts[i + 1]) elif match.endswith("F"): + front += "%x" + TOKEN + "%x" back += DOUBLE_HEX.format(parts[i + 1]) else: - back += ", {}".format(parts[i+1]) + front += match + back += ", {}".format(parts[i + 1]) front += '", {}'.format(self._message_id) back += ");" return original, front + back From 13ba93304756222f218ffa4ee0df90cdb2fa35aa Mon Sep 17 00:00:00 2001 From: christian-B Date: Fri, 18 Dec 2020 07:35:45 +0000 Subject: [PATCH 12/18] test double dict errors --- unittests/matrix/test_double.py | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/unittests/matrix/test_double.py b/unittests/matrix/test_double.py index 6efa71fa..e5f7dce8 100644 --- a/unittests/matrix/test_double.py +++ b/unittests/matrix/test_double.py @@ -50,3 +50,39 @@ def test_singleSet_inverted(): double[1] = new_data assert double["foo"][1] == "One" assert double[1]["bar"] == "Two" + +def test_errors(): + matrix = DemoMatrix() + double = DoubleDict(xtype=str, ytype=int, matrix=matrix) + new_data = {"foo": "One", "bar": "Two"} + double[1] = new_data + try: + double[1.1] + assert False + except KeyError as ex: + assert "unexpected type" in str(ex) + try: + double["Bar"] = "Opps" + except ValueError as ex: + assert "Value must of type dict" in str(ex) + try: + double["Bar"] = [2, "Opps"] + assert False + except ValueError as ex: + assert "Value must of type dict" in str(ex) + try: + double["Bar"] = {2.1: "Opps"} + assert False + except ValueError as ex: + assert "All keys in the value" in str(ex) + try: + double[2] = {1: "Opps"} + assert False + except ValueError as ex: + assert "All keys in the value" in str(ex) + try: + double[2.1] = {1: "Opps"} + assert False + except KeyError as ex: + assert "unexpected type" in str(ex) + From 8fafe13c2c78c05ac1ccbe4c52145c1b12fea551 Mon Sep 17 00:00:00 2001 From: christian-B Date: Fri, 18 Dec 2020 08:44:52 +0000 Subject: [PATCH 13/18] python 2 weirdness --- spinn_utilities/default_ordered_dict.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/spinn_utilities/default_ordered_dict.py b/spinn_utilities/default_ordered_dict.py index 256a3370..a3a036ba 100644 --- a/spinn_utilities/default_ordered_dict.py +++ b/spinn_utilities/default_ordered_dict.py @@ -18,6 +18,7 @@ from collections.abc import Callable except ImportError: from collections import Callable +from six import PY2 class DefaultOrderedDict(OrderedDict): @@ -47,7 +48,11 @@ def __reduce__(self): args = tuple() else: args = self.default_factory, - return type(self), args, None, None, iter(self.items()) + if PY2: + return type(self), args, None, None, self.items() + else: + return type(self), args, None, None, iter(self.items()) + def copy(self): return self.__copy__() @@ -57,8 +62,12 @@ def __copy__(self): def __deepcopy__(self, memo): import copy - return type(self)(self.default_factory, - copy.deepcopy(iter(self.items()))) + if PY2: + return type(self)(self.default_factory, + copy.deepcopy(self.items())) + else: + return type(self)(self.default_factory, + copy.deepcopy(iter(self.items()))) def __repr__(self): return 'OrderedDefaultDict(%s, %s)' % ( From 96ba7dd16059c5e2c68d0369d15021874ea22e0a Mon Sep 17 00:00:00 2001 From: christian-B Date: Fri, 18 Dec 2020 08:48:54 +0000 Subject: [PATCH 14/18] flake8 --- unittests/make_tools/test_file_convert.py | 2 +- unittests/make_tools/test_replacer.py | 3 ++- unittests/matrix/test_double.py | 2 +- unittests/test_conf_loader.py | 9 ++++----- unittests/test_default_ordered_dict.py | 2 ++ unittests/test_log.py | 2 ++ 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/unittests/make_tools/test_file_convert.py b/unittests/make_tools/test_file_convert.py index 9288e425..24f7e14d 100644 --- a/unittests/make_tools/test_file_convert.py +++ b/unittests/make_tools/test_file_convert.py @@ -66,7 +66,7 @@ def test_exceptions(self): src = os.path.join("mock_src", file_name) dest = os.path.join("modified_src", file_name) dict = dest + "dict" - convertor = FileConverter(src, dest, dict) + convertor = FileConverter(src, dest, dict) try: convertor.split_by_comma_plus(None, 12) assert False diff --git a/unittests/make_tools/test_replacer.py b/unittests/make_tools/test_replacer.py index dc5e7f51..e7f4ce70 100644 --- a/unittests/make_tools/test_replacer.py +++ b/unittests/make_tools/test_replacer.py @@ -53,7 +53,8 @@ def test_float(self): def test_double(self): replacer = Replacer(os.path.join(PATH, "test")) - new = replacer.replace("1022" + TOKEN + "40379999" + TOKEN + "9999999a") + new = replacer.replace( + "1022" + TOKEN + "40379999" + TOKEN + "9999999a") message = "[INFO] (weird;file.c: 34): a double 23.6" assert (message == new) diff --git a/unittests/matrix/test_double.py b/unittests/matrix/test_double.py index e5f7dce8..2e54c083 100644 --- a/unittests/matrix/test_double.py +++ b/unittests/matrix/test_double.py @@ -51,6 +51,7 @@ def test_singleSet_inverted(): assert double["foo"][1] == "One" assert double[1]["bar"] == "Two" + def test_errors(): matrix = DemoMatrix() double = DoubleDict(xtype=str, ytype=int, matrix=matrix) @@ -85,4 +86,3 @@ def test_errors(): assert False except KeyError as ex: assert "unexpected type" in str(ex) - diff --git a/unittests/test_conf_loader.py b/unittests/test_conf_loader.py index c17ab546..d235932a 100644 --- a/unittests/test_conf_loader.py +++ b/unittests/test_conf_loader.py @@ -126,16 +126,15 @@ def test_types(tmpdir, default_config): f.write(default_config) config = conf_loader.load_config( CFGFILE, [CFGPATH], validation_cfg="blank.cfg") - a = config.get_int("machine", "version") assert config.get_int("machine", "version") == 5 - assert config.get_int("machine", "oops") == None - assert config.get_float("machine","size") == 4.6 - assert config.get_float("machine","oops") == None + assert config.get_int("machine", "oops") is None + assert config.get_float("machine", "size") == 4.6 + assert config.get_float("machine", "oops") is None assert config.get_bool("machine", "b1") assert config.get_bool("machine", "b2") assert not config.get_bool("machine", "b3") assert not config.get_bool("machine", "b4") - assert config.get_bool("machine","oops") == None + assert config.get_bool("machine", "oops") is None def test_dead_section(tmpdir, default_config): diff --git a/unittests/test_default_ordered_dict.py b/unittests/test_default_ordered_dict.py index c81b823d..33d99a61 100644 --- a/unittests/test_default_ordered_dict.py +++ b/unittests/test_default_ordered_dict.py @@ -56,6 +56,7 @@ def test_keys_in_order(): assert a == b == c assert tuple(o) == ("a", "b", "c") + def test_callable(): try: DefaultOrderedDict("Not callable") @@ -63,6 +64,7 @@ def test_callable(): except TypeError: pass + def test_special_methods(): o = DefaultOrderedDict(list) o["gamma"].append("bacon") diff --git a/unittests/test_log.py b/unittests/test_log.py index 80eef663..92fe1e24 100644 --- a/unittests/test_log.py +++ b/unittests/test_log.py @@ -112,6 +112,7 @@ def test_weird_config1(): ConfiguredFormatter(MockConfig1()) ConfiguredFilter(MockConfig1()) + class MockConfig2(): def get(self, section, option): @@ -123,6 +124,7 @@ def has_section(self, section): def has_option(self, section, option): return option == 'warning' + def test_weird_config2(): ConfiguredFormatter(MockConfig2()) ConfiguredFilter(MockConfig2()) From 6f8b9f5c2e118e2c4122d68a2dce31eee0be00d2 Mon Sep 17 00:00:00 2001 From: christian-B Date: Fri, 18 Dec 2020 09:39:41 +0000 Subject: [PATCH 15/18] flake8 --- spinn_utilities/default_ordered_dict.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spinn_utilities/default_ordered_dict.py b/spinn_utilities/default_ordered_dict.py index a3a036ba..04e9ea52 100644 --- a/spinn_utilities/default_ordered_dict.py +++ b/spinn_utilities/default_ordered_dict.py @@ -53,7 +53,6 @@ def __reduce__(self): else: return type(self), args, None, None, iter(self.items()) - def copy(self): return self.__copy__() From bfc73f745358dc0fd1402f229f3688b4acfdaa3e Mon Sep 17 00:00:00 2001 From: christian-B Date: Tue, 5 Jan 2021 06:52:28 +0000 Subject: [PATCH 16/18] fixed repr --- spinn_utilities/default_ordered_dict.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spinn_utilities/default_ordered_dict.py b/spinn_utilities/default_ordered_dict.py index 04e9ea52..73f649ba 100644 --- a/spinn_utilities/default_ordered_dict.py +++ b/spinn_utilities/default_ordered_dict.py @@ -69,5 +69,5 @@ def __deepcopy__(self, memo): copy.deepcopy(iter(self.items()))) def __repr__(self): - return 'OrderedDefaultDict(%s, %s)' % ( + return 'DefaultOrderedDict(%s, %s)' % ( self.default_factory, OrderedDict.__repr__(self)) From e65e7d62357908a7b79ae49724febdbc94990d63 Mon Sep 17 00:00:00 2001 From: alan-stokes Date: Fri, 5 Feb 2021 13:50:49 +0000 Subject: [PATCH 17/18] everything in the end meets objects --- unittests/test_log.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/unittests/test_log.py b/unittests/test_log.py index 633d1a16..04e94709 100644 --- a/unittests/test_log.py +++ b/unittests/test_log.py @@ -99,7 +99,7 @@ class Exn(Exception): assert len(logger._repeat_log()) == 1 -class MockConfig1(): +class MockConfig1(object): def get(self, section, option): return "debug" @@ -113,7 +113,7 @@ def test_weird_config1(): ConfiguredFilter(MockConfig1()) -class MockConfig2(): +class MockConfig2(object): def get(self, section, option): return "critical" From d3e1e2360b7b7b5f07eca1a3ad1425035a02869f Mon Sep 17 00:00:00 2001 From: "Christian Y. Brenninkmeijer" Date: Mon, 15 Feb 2021 08:05:10 +0000 Subject: [PATCH 18/18] copy fixes --- spinn_utilities/default_ordered_dict.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spinn_utilities/default_ordered_dict.py b/spinn_utilities/default_ordered_dict.py index ed8ca7a7..5e4f29e3 100644 --- a/spinn_utilities/default_ordered_dict.py +++ b/spinn_utilities/default_ordered_dict.py @@ -44,18 +44,17 @@ def __reduce__(self): args = tuple() else: args = self.default_factory, - return type(self), args, None, None, self.items() + return type(self), args, None, None, iter(self.items()) def copy(self): - return self.__copy__() + return type(self)(self.default_factory, self.items()) - def __copy__(self): - return type(self)(self.default_factory, self) + __copy__ = copy def __deepcopy__(self, memo): import copy return type(self)(self.default_factory, - copy.deepcopy(self.items())) + copy.deepcopy(iter(self.items()))) def __repr__(self): return 'DefaultOrderedDict(%s, %s)' % (