示例#1
0
    def test_diff(self):
        P1 = ConfigParserParameterSet(self.__class__.test_parameters)
        P2 = ConfigParserParameterSet(
            dedent("""
            # this is a comment

            [sectionA]
            a: 3
            b: 3

            [sectionB]
            c: hello
            d: universe

            [sectionC]
            e: zebra
            """))
        self.assertEqual(P1.diff(P2), ({
            'sectionA': {
                'a': '2'
            },
            'sectionB': {
                'd': 'world'
            }
        }, {
            'sectionA': {
                'a': '3'
            },
            'sectionB': {
                'd': 'universe'
            },
            'sectionC': {
                'e': 'zebra'
            }
        }))
示例#2
0
 def test__init__should_accept_a_filename_or_string(self):
     init = self.__class__.test_parameters
     P1 = ConfigParserParameterSet(init)
     with open("test_file", "w") as f:
         f.write(init)
     P2 = ConfigParserParameterSet("test_file")
     self.assertEqual(P1.as_dict(), P2.as_dict())
     os.remove("test_file")
示例#3
0
 def test__update_should_handle_dots_appropriately(self):
     init = self.__class__.test_parameters
     P = ConfigParserParameterSet(init)
     P.update({"sectionA.a": 5, "sectionA.c": 4, "sectionC.e": 9})
     self.assertEqual(
         P.as_dict(), {
             "sectionA": dict(a="5", b="3", c="4"),
             "sectionB": dict(c="hello", d="world"),
             "sectionC": dict(e="9")
         })
示例#4
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)
示例#5
0
 def test__getitem(self):
     init = self.__class__.test_parameters
     P = ConfigParserParameterSet(init)
     self.assertEqual(P['sectionA'], {'a': '2', 'b': '3'})
     self.assertEqual(P['sectionB.c'], 'hello')
示例#6
0
 def test__pop(self):
     init = self.__class__.test_parameters
     P = ConfigParserParameterSet(init)
     self.assertEqual(P.pop('sectionA.b'), '3')
     self.assertEqual(P.pop('sectionA.foo', 42), 42)
示例#7
0
 def test__str(self):
     init = self.__class__.test_parameters
     P = ConfigParserParameterSet(str(init))
     as_string = str(P)
     self.assertIsInstance(as_string, str)
     self.assertEqual(P, ConfigParserParameterSet(as_string))
示例#8
0
 def test__deepcopy(self):
     # see ticket:93
     init = self.__class__.test_parameters
     P = ConfigParserParameterSet(init)
     Q = deepcopy(P)
示例#9
0
 def test__pretty__output_should_be_useable_to_create_an_identical_parameterset(
         self):
     init = self.__class__.test_parameters
     P1 = ConfigParserParameterSet(init)
     P2 = ConfigParserParameterSet(P1.pretty())
     self.assertEqual(P1.as_dict(), P2.as_dict())
示例#10
0
 def test__init__should_accept_an_empty_initializer(self):
     P = ConfigParserParameterSet("")
     self.assertEqual(P.as_dict(), {})