コード例 #1
0
 def test_setup_definitions_1(self):
     s = dotdict.DotDict()
     s.x = option.Option('x', 17, 'the x')
     s.n = {'name': 'n', 'doc': 'the n', 'default': 23}
     s.__forbidden__ = option.Option(
         '__forbidden__',
         'no, you cannot',
         38
     )
     s.t = namespace.Namespace()
     s.t.add_option('kk', 999, 'the kk')
     s.w = 89
     s.z = None
     s.t2 = namespace.Namespace('empty namespace')
     d = dotdict.DotDict()
     for_mappings.setup_definitions(s, d)
     self.assertEqual(len(d), 6)
     self.assertTrue(isinstance(d.x, option.Option))
     self.assertTrue(isinstance(d.n, option.Option))
     self.assertTrue(d.n.name == 'n')
     self.assertTrue(d.n.default == 23)
     self.assertTrue(d.n.doc == 'the n')
     self.assertTrue(isinstance(d.t, namespace.Namespace))
     self.assertTrue(d.t.kk.name == 'kk')
     self.assertTrue(d.t.kk.default == 999)
     self.assertTrue(d.t.kk.doc == 'the kk')
     self.assertTrue(isinstance(d.w, namespace.Option))
     self.assertTrue(d.w.name == 'w')
     self.assertTrue(d.w.default == 89)
     self.assertTrue(d.w.doc == 'w')
     self.assertTrue(isinstance(d.t2, namespace.Namespace))
     self.assertTrue(len(d.t2) == 0)
コード例 #2
0
def setup_definitions(source, destination):
    try:
        json_dict = json.loads(source)
    except ValueError:
        with open(source) as j:
            json_dict = json.load(j)
    for_mappings.setup_definitions(json_dict, destination)
コード例 #3
0
 def test_setup_definitions_1(self):
     s = dotdict.DotDict()
     s.x = option.Option('x', 17, 'the x')
     s.n = {'name': 'n', 'doc': 'the n', 'default': 23}
     s.__forbidden__ = option.Option('__forbidden__', 'no, you cannot', 38)
     s.t = namespace.Namespace()
     s.t.add_option('kk', 999, 'the kk')
     s.w = 89
     s.z = None
     s.t2 = namespace.Namespace('empty namespace')
     d = dotdict.DotDict()
     for_mappings.setup_definitions(s, d)
     self.assertEqual(len(d), 6)
     self.assertTrue(isinstance(d.x, option.Option))
     self.assertTrue(isinstance(d.n, option.Option))
     self.assertTrue(d.n.name == 'n')
     self.assertTrue(d.n.default == 23)
     self.assertTrue(d.n.doc == 'the n')
     self.assertTrue(isinstance(d.t, namespace.Namespace))
     self.assertTrue(d.t.kk.name == 'kk')
     self.assertTrue(d.t.kk.default == 999)
     self.assertTrue(d.t.kk.doc == 'the kk')
     self.assertTrue(isinstance(d.w, namespace.Option))
     self.assertTrue(d.w.name == 'w')
     self.assertTrue(d.w.default == 89)
     self.assertTrue(d.w.doc == 'w')
     self.assertTrue(isinstance(d.t2, namespace.Namespace))
     self.assertTrue(len(d.t2) == 0)
コード例 #4
0
ファイル: for_json.py プロジェクト: mozilla/configman
def setup_definitions(source, destination):
    try:
        json_dict = json.loads(source)
    except ValueError:
        with open(source) as j:
            json_dict = json.load(j)
    for_mappings.setup_definitions(json_dict, destination)
コード例 #5
0
def setup_definitions(source, destination):
    module_dict = source.__dict__.copy()
    del module_dict['__builtins__']
    setup_definitions(module_dict, destination)