コード例 #1
0
ファイル: test_dotdict.py プロジェクト: rfw/configman
    def test_iteritems_breadth_first(self):
        d = {'a': {'aa': 13,
                   'ab': 14,},
             'b': {'ba': {'baa': 0,
                          'bab': 1,},
                   'bb': {'bba': 2,}},
             'c': 9,
             'd': {'dd': 2}}
        e = [('a.aa', 13),
             ('a.ab', 14),
             ('b.ba.baa', 0),
             ('b.ba.bab', 1),
             ('b.bb.bba', 2),
             ('c', 9),
             ('d.dd', 2)]
        a = [x for x in iteritems_breadth_first(d)]
        e = sorted(e)
        a = sorted(a)
        self.assertEqual(a, e)

        # try a round trip
        dd = DotDict()
        for k, v in a:
            print k, v
            dd.assign(k, v)
        ddkv = sorted(iteritems_breadth_first(dd))
        self.assertEqual(e, ddkv)
コード例 #2
0
ファイル: test_dotdict.py プロジェクト: ahal/configman
    def test_iteritems_breadth_first(self):
        d = {
            'a': {
                'aa': 13,
                'ab': 14
            },
            'b': {
                'ba': {
                    'baa': 0,
                    'bab': 1
                },
                'bb': {
                    'bba': 2
                }
            },
            'c': 9,
            'd': {
                'dd': 2
            }
        }
        e = [('a.aa', 13), ('a.ab', 14), ('b.ba.baa', 0), ('b.ba.bab', 1),
             ('b.bb.bba', 2), ('c', 9), ('d.dd', 2)]
        a = [x for x in iteritems_breadth_first(d)]
        e = sorted(e)
        a = sorted(a)
        self.assertEqual(a, e)

        # try a round trip
        dd = DotDict()
        for k, v in a:
            dd.assign(k, v)
        ddkv = sorted(iteritems_breadth_first(dd))
        self.assertEqual(e, ddkv)
コード例 #3
0
ファイル: test_dotdict.py プロジェクト: GabiThume/configman
    def test_iteritems_breadth_first(self):
        d = {"a": {"aa": 13, "ab": 14}, "b": {"ba": {"baa": 0, "bab": 1}, "bb": {"bba": 2}}, "c": 9, "d": {"dd": 2}}
        e = [("a.aa", 13), ("a.ab", 14), ("b.ba.baa", 0), ("b.ba.bab", 1), ("b.bb.bba", 2), ("c", 9), ("d.dd", 2)]
        a = [x for x in iteritems_breadth_first(d)]
        e = sorted(e)
        a = sorted(a)
        self.assertEqual(a, e)

        # try a round trip
        dd = DotDict()
        for k, v in a:
            dd.assign(k, v)
        ddkv = sorted(iteritems_breadth_first(dd))
        self.assertEqual(e, ddkv)
コード例 #4
0
ファイル: test_dotdict.py プロジェクト: ahal/configman
 def test_copy_constructor_2(self):
     d = {
         'a': {
             'aa': 13,
             'ab': 14
         },
         'b': {
             'ba': {
                 'baa': 0,
                 'bab': 1
             },
             'bb': {
                 'bba': 2
             }
         },
         'c': 9,
         'd': {
             'dd': 2
         }
     }
     dd = DotDictWithAcquisition(d)
     e = [('a.aa', 13), ('a.ab', 14), ('b.ba.baa', 0), ('b.ba.bab', 1),
          ('b.bb.bba', 2), ('c', 9), ('d.dd', 2)]
     a = [x for x in iteritems_breadth_first(d)]
     e = sorted(e)
     a = sorted(a)
     self.assertEqual(a, e)
     self.assertTrue(isinstance(dd.a, DotDictWithAcquisition))
コード例 #5
0
ファイル: for_argparse.py プロジェクト: mozilla/configman
 def get_required_config(self):
     """because of the exsistance of subparsers, the configman options
     that correspond with argparse arguments are not a constant.  We need
     to produce a copy of the namespace rather than the actual embedded
     namespace."""
     required_config = Namespace()
     # add current options to a copy of required config
     for k, v in iteritems_breadth_first(self.required_config):
         required_config[k] = v
     # get any option found in any subparsers
     try:
         subparser_namespaces = (
             self.configman_subparsers_option.foreign_data
             .argparse.subprocessor_from_string_converter
         )
         subparsers = (
             self._argparse_subparsers._configman_option.foreign_data
             .argparse.subparsers
         )
         # each subparser needs to have its configman options set up
         # in the subparser's configman option.  This routine copies
         # the required_config of each subparser into the
         # SubparserFromStringConverter defined above.
         for subparser_name, subparser_data in six.iteritems(subparsers):
             subparser_namespaces.add_namespace(
                 subparser_name,
                 subparser_data.subparser.get_required_config()
             )
     except AttributeError:
         # there is no subparser
         pass
     return required_config
コード例 #6
0
 def get_required_config(self):
     """because of the exsistance of subparsers, the configman options
     that correspond with argparse arguments are not a constant.  We need
     to produce a copy of the namespace rather than the actual embedded
     namespace."""
     required_config = Namespace()
     # add current options to a copy of required config
     for k, v in iteritems_breadth_first(self.required_config):
         required_config[k] = v
     # get any option found in any subparsers
     try:
         subparser_namespaces = (
             self.configman_subparsers_option.foreign_data.argparse.
             subprocessor_from_string_converter)
         subparsers = (self._argparse_subparsers._configman_option.
                       foreign_data.argparse.subparsers)
         # each subparser needs to have its configman options set up
         # in the subparser's configman option.  This routine copies
         # the required_config of each subparser into the
         # SubparserFromStringConverter defined above.
         for subparser_name, subparser_data in six.iteritems(subparsers):
             subparser_namespaces.add_namespace(
                 subparser_name,
                 subparser_data.subparser.get_required_config())
     except AttributeError:
         # there is no subparser
         pass
     return required_config
コード例 #7
0
ファイル: test_dotdict.py プロジェクト: GabiThume/configman
 def test_copy_constructor_2(self):
     d = {"a": {"aa": 13, "ab": 14}, "b": {"ba": {"baa": 0, "bab": 1}, "bb": {"bba": 2}}, "c": 9, "d": {"dd": 2}}
     dd = DotDictWithAcquisition(d)
     e = [("a.aa", 13), ("a.ab", 14), ("b.ba.baa", 0), ("b.ba.bab", 1), ("b.bb.bba", 2), ("c", 9), ("d.dd", 2)]
     a = [x for x in iteritems_breadth_first(d)]
     e = sorted(e)
     a = sorted(a)
     self.assertEqual(a, e)
     self.assertTrue(isinstance(dd.a, DotDictWithAcquisition))
コード例 #8
0
ファイル: test_dotdict.py プロジェクト: rfw/configman
 def  test_copy_constructor(self):
     d = {'a': {'aa': 13,
                'ab': 14,},
          'b': {'ba': {'baa': 0,
                'bab': 1,},
                'bb': {'bba': 2,}},
          'c': 9,
          'd': {'dd': 2}}
     dd = DotDictWithAcquisition(d)
     e = [('a.aa', 13),
          ('a.ab', 14),
          ('b.ba.baa', 0),
          ('b.ba.bab', 1),
          ('b.bb.bba', 2),
          ('c', 9),
          ('d.dd', 2)]
     a = [x for x in iteritems_breadth_first(d)]
     e = sorted(e)
     a = sorted(a)
     self.assertEqual(a, e)
     self.assertTrue(isinstance(dd.a, DotDictWithAcquisition))