def test_save(self): init = self.__class__.test_parameters P1 = YAMLParameterSet(init) P1.save("test_file") P2 = YAMLParameterSet("test_file") self.assertEqual(P1.as_dict(), P2.as_dict()) os.remove("test_file")
def test_save(self): init = self.__class__.test_parameters P1 = YAMLParameterSet(init) P1.save("test_file") P2 = YAMLParameterSet("test_file") self.assertEqual(P1.as_dict(), P2.as_dict()) os.remove("test_file")
def test__init__should_accept_a_filename_or_string(self): init = self.__class__.test_parameters P1 = YAMLParameterSet(init) with open("test_file", "w") as f: f.write(init) P2 = YAMLParameterSet("test_file") self.assertEqual(P1.as_dict(), P2.as_dict()) os.remove("test_file")
def test__init__should_accept_a_filename_or_string(self): init = self.__class__.test_parameters P1 = YAMLParameterSet(init) with open("test_file", "w") as f: f.write(init) P2 = YAMLParameterSet("test_file") self.assertEqual(P1.as_dict(), P2.as_dict()) os.remove("test_file")
def test__pop(self): init = self.__class__.test_parameters P = YAMLParameterSet(init) self.assertEqual(P.pop('a'), 2) self.assertEqual(P.pop('c'), {"a": 1, "b": 2}) self.assertEqual(P.as_dict(), {'b': "hello", "d": [1, 2, 3, 4]}) self.assertEqual(P.pop('foo', 42), 42) self.assertEqual(P.pop('foo', None), None)
def test__pop(self): init = self.__class__.test_parameters P = YAMLParameterSet(init) self.assertEqual(P.pop('a'), 2) self.assertEqual(P.pop('c'), {"a": 1, "b": 2}) self.assertEqual(P.as_dict(), {'b': "hello", "d": [1, 2, 3, 4]}) self.assertEqual(P.pop('foo', 42), 42) self.assertEqual(P.pop('foo', None), None)
def test__as_dict(self): init = self.__class__.test_parameters P = YAMLParameterSet(init) self.assertEqual(P.as_dict(), { "a": 2, "b": "hello", "c": {"a": 1, "b": 2}, "d": [1, 2, 3, 4] })
def test__as_dict(self): init = self.__class__.test_parameters P = YAMLParameterSet(init) self.assertEqual(P.as_dict(), { "a": 2, "b": "hello", "c": { "a": 1, "b": 2 }, "d": [1, 2, 3, 4] })
def test__pretty__output_should_be_useable_to_create_an_identical_parameterset(self): init = self.__class__.test_parameters P1 = YAMLParameterSet(init) P2 = YAMLParameterSet(P1.pretty()) self.assertEqual(P1.as_dict(), P2.as_dict())
def test__init__should_accept_an_empty_initializer(self): P = YAMLParameterSet("") self.assertEqual(P.as_dict(), {})
def test__pretty__output_should_be_useable_to_create_an_identical_parameterset( self): init = self.__class__.test_parameters P1 = YAMLParameterSet(init) P2 = YAMLParameterSet(P1.pretty()) self.assertEqual(P1.as_dict(), P2.as_dict())
def test__init__should_accept_an_empty_initializer(self): P = YAMLParameterSet("") self.assertEqual(P.as_dict(), {})