Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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")
Ejemplo n.º 3
0
 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]
                      })
Ejemplo n.º 4
0
 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]
     })
Ejemplo n.º 5
0
 def test_diff(self):
     P1 = YAMLParameterSet(self.__class__.test_parameters)
     P2 = YAMLParameterSet(dedent("""
         a:   3
         b:   "hello"
         c:
           a: 1
           b: 22
         d:   [1, 2, 77, 4]
     """))
     self.assertEqual(P1.diff(P2),
                      ({'a': 2, 'c': {'b': 2}, 'd': [1, 2, 3, 4]},
                       {'a': 3, 'c': {'b': 22}, 'd': [1, 2, 77, 4]}))
Ejemplo n.º 6
0
 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")
Ejemplo n.º 7
0
 def test_diff(self):
     P1 = JSONParameterSet(self.__class__.test_parameters)
     P2 = JSONParameterSet(
         dedent("""
     {
         "a" : 3,
         "b" : "hello",
         "c" : {"a": 1, "b": 22},
         "d" : [1, 2, 77, 4]
     }
     """))
     self.assertEqual(P1.diff(P2), ({
         'a': 2,
         'c': {
             'b': 2
         },
         'd': [1, 2, 3, 4]
     }, {
         'a': 3,
         'c': {
             'b': 22
         },
         'd': [1, 2, 77, 4]
     }))
     try:
         P3 = YAMLParameterSet(TestYAMLParameterSet.test_parameters)
     except ImportError:
         pass
     else:
         self.assertEqual(P2.diff(P3), P2.diff(P1))
Ejemplo n.º 8
0
 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")
Ejemplo n.º 9
0
 def setUp(self):
     ## setup parsets with legal params
     self.PSETS = [SimpleParameterSet(""), JSONParameterSet("")]
     try:
         self.PSETS.append(YAMLParameterSet(""))
     except ImportError:
         pass
     self.PConfigParser = ConfigParserParameterSet("")
     for k in ('a', 'b', 'c', 'd', 'l', 'save'):
         up_dict = {k: 1}
         self.PConfigParser.update(up_dict)
         for P in self.PSETS:
             P.update(up_dict)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
 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")
Ejemplo n.º 12
0
 def test_diff(self):
     P1 = YAMLParameterSet(self.__class__.test_parameters)
     P2 = YAMLParameterSet(
         dedent("""
         a:   3
         b:   "hello"
         c:
           a: 1
           b: 22
         d:   [1, 2, 77, 4]
     """))
     self.assertEqual(P1.diff(P2), ({
         'a': 2,
         'c': {
             'b': 2
         },
         'd': [1, 2, 3, 4]
     }, {
         'a': 3,
         'c': {
             'b': 22
         },
         'd': [1, 2, 77, 4]
     }))
Ejemplo n.º 13
0
 def test__update(self):
     P = YAMLParameterSet(self.__class__.test_parameters)
     P.update([("x", 1), ("y", 2)], z=3)
     self.assertEqual(P["z"], 3)
Ejemplo n.º 14
0
 def test_equality(self):
     P = YAMLParameterSet(self.__class__.test_parameters)
     Q = YAMLParameterSet(self.__class__.test_parameters)
     self.assertEqual(P, Q)
     Q.update({"a": 3})
     self.assertNotEqual(P, Q)
Ejemplo n.º 15
0
 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())
Ejemplo n.º 16
0
 def test__str(self):
     init = self.__class__.test_parameters
     P = YAMLParameterSet(init)
     as_string = str(P)
     self.assertIsInstance(as_string, str)
Ejemplo n.º 17
0
 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())
Ejemplo n.º 18
0
 def test_equality(self):
     P = YAMLParameterSet(self.__class__.test_parameters)
     Q = YAMLParameterSet(self.__class__.test_parameters)
     self.assertEqual(P, Q)
     Q.update({"a": 3})
     self.assertNotEqual(P, Q)
Ejemplo n.º 19
0
 def test__init__should_accept_an_empty_initializer(self):
     P = YAMLParameterSet("")
     self.assertEqual(P.as_dict(), {})
Ejemplo n.º 20
0
 def test__init__should_accept_an_empty_initializer(self):
     P = YAMLParameterSet("")
     self.assertEqual(P.as_dict(), {})
Ejemplo n.º 21
0
 def test__update(self):
     P = YAMLParameterSet(self.__class__.test_parameters)
     P.update([("x", 1), ("y", 2)], z=3)
     self.assertEqual(P["z"], 3)