当前位置: 首页>>代码示例>>Python>>正文


Python Cfg.new_by_json_str方法代码示例

本文整理汇总了Python中rmtoo.lib.configuration.Cfg.Cfg.new_by_json_str方法的典型用法代码示例。如果您正苦于以下问题:Python Cfg.new_by_json_str方法的具体用法?Python Cfg.new_by_json_str怎么用?Python Cfg.new_by_json_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rmtoo.lib.configuration.Cfg.Cfg的用法示例。


在下文中一共展示了Cfg.new_by_json_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_json_init_add_new_cmd_line_params

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
    def test_json_init_add_new_cmd_line_params(self):
        '''Init Cfg with JSON and adds parameters with command line options'''
        mstderr = StringIO.StringIO()
        init_logger(mstderr)

        # Create two JSON files.
        tmpdir = create_tmp_dir()
        jsonfile1 = os.path.join(tmpdir, "config1.json")
        jsonfd1 = file(jsonfile1, "w")
        jsonfd1.write(json.dumps({'k': 2 , 'm': {'n': 5}, 'o': 7}))
        jsonfd1.close()
        jsonfile2 = os.path.join(tmpdir, "config2.json")
        jsonfd2 = file(jsonfile2, "w")
        jsonfd2.write(json.dumps({'k': 3 , 'm': {'w': 11}, 'p': 9}))
        jsonfd2.close()

        config = Cfg.new_by_json_str('{"k": 1, "l": [2, 3], "m": {"n": 4}}');
        config.merge_cmd_line_params(['-j', '{"m": {"p": 99}}',
                                      '-j', 'file://' + jsonfile1,
                                      '-j', '{"m": {"q": 100}}',
                                      '-j', 'file://' + jsonfile2])
        self.failUnlessEqual(1, config.get_value("k"), "k is not 1")
        config.evaluate()
        self.failUnlessEqual(3, config.get_value("k"), "k is not 3")
        self.failUnlessEqual(11, config.get_value("m.w"))
        lstderr = hide_timestamp(mstderr.getvalue())
        tear_down_log_handler()
        self.failUnlessEqual(lstderr, "")
开发者ID:CrypticGator,项目名称:rmtoo,代码行数:30,代码来源:TestConfiguration.py

示例2: test_neg_05

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
    def test_neg_05(self):
        "TestRecordTxt2: long long line - check for lineno"
        mstderr = StringIO.StringIO()
        init_logger(mstderr)

        cfg = Cfg.new_by_json_str('{"max_input_line_length": 7}')
        tioconfig = TxtIOConfig(cfg)
        txt_doc = TxtRecord.from_string("""# com
ok: yes
 no
# cs
# dds
good: but too long
# dds

""",
                                        "TooLong", tioconfig)

        self.assertEqual(txt_doc.is_usable(), False)
        lstderr = hide_timestamp(mstderr.getvalue())
        tear_down_log_handler()
        
        result_expected = "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;" \
        "check_line_length;77; 80:TooLong:6:line too long: is [18], " \
        "max allowed [7]\n"
        self.assertEquals(result_expected, lstderr)
开发者ID:CrypticGator,项目名称:rmtoo,代码行数:28,代码来源:TestRecordTxt2.py

示例3: test_json_init_add_new_cmd_line_params

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
    def test_json_init_add_new_cmd_line_params(self):
        '''Init Cfg with JSON and adds parameters with command line options'''
        log_store = MemLogStore()

        # Create two JSON files.
        tmpdir = create_tmp_dir()
        jsonfile1 = os.path.join(tmpdir, "config1.json")
        jsonfd1 = file(jsonfile1, "w")
        jsonfd1.write(json.dumps({'k': 2 , 'm': {'n': 5}, 'o': 7}))
        jsonfd1.close()
        jsonfile2 = os.path.join(tmpdir, "config2.json")
        jsonfd2 = file(jsonfile2, "w")
        jsonfd2.write(json.dumps({'k': 3 , 'm': {'w': 11}, 'p': 9}))
        jsonfd2.close()

        config = Cfg.new_by_json_str('{"k": 1, "l": [2, 3], "m": {"n": 4}}');
        config.merge_cmd_line_params(['-j', '{"m": {"p": 99}}',
                                      '-j', 'file://' + jsonfile1,
                                      '-j', '{"m": {"q": 100}}',
                                      '-j', 'file://' + jsonfile2])
        self.failUnlessEqual(1, config.get_value("k"), "k is not 1")
        config.evaluate(log_store)
        self.failUnlessEqual(3, config.get_value("k"), "k is not 3")
        self.failUnlessEqual(11, config.get_value("m.w"))
        self.failUnlessEqual(MemLogStore.create_mls([]), log_store)
开发者ID:oscarpicas,项目名称:rmtoo,代码行数:27,代码来源:TestConfiguration.py

示例4: rmttest_json_init_add_new_cmd_line_params

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
    def rmttest_json_init_add_new_cmd_line_params(self):
        '''Init Cfg with JSON and adds parameters with command line options'''
        mstderr = StringIO()
        init_logger(mstderr)

        # Create two JSON files.
        tmpdir = create_tmp_dir()
        jsonfile1 = os.path.join(tmpdir, "config1.json")
        with open(jsonfile1, "w") as jsonfd1:
            jsonfd1.write(json.dumps({'k': 2, 'm': {'n': 5}, 'o': 7}))

        jsonfile2 = os.path.join(tmpdir, "config2.json")
        with open(jsonfile2, "w") as jsonfd2:
            jsonfd2.write(json.dumps({'k': 3, 'm': {'w': 11}, 'p': 9}))

        config = Cfg.new_by_json_str('{"k": 1, "l": [2, 3], "m": {"n": 4}}')
        config.merge_cmd_line_params(['-j', '{"m": {"p": 99}}',
                                      '-j', 'file://' + jsonfile1,
                                      '-j', '{"m": {"q": 100}}',
                                      '-j', 'file://' + jsonfile2])
        assert 1 == config.get_value("k"), "k is not 1"
        config.evaluate()
        assert 3 == config.get_value("k"), "k is not 3"
        assert 11 == config.get_value("m.w")
        lstderr = hide_volatile(mstderr.getvalue())
        shutil.rmtree(tmpdir)
        tear_down_log_handler()
        assert lstderr == ""
开发者ID:florath,项目名称:rmtoo,代码行数:30,代码来源:RMTTest-Configuration.py

示例5: test_dollar_replacement_environment_variables

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
 def test_dollar_replacement_environment_variables(self):
     '''Check if the $ replacement works with environment variables.'''
     os.environ["huho"] = "ThereIsSomeVal"
     config = Cfg.new_by_json_str('{"k": "${ENV:huho}"}')
     val = config.get_rvalue("k")
     os.environ["huho"] = ""
     self.failUnlessEqual("ThereIsSomeVal", val,
                          "k is not ThereIsSomeVal")
开发者ID:CrypticGator,项目名称:rmtoo,代码行数:10,代码来源:TestConfiguration.py

示例6: rmttest_dollar_replacement_environment_variables

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
 def rmttest_dollar_replacement_environment_variables(self):
     '''Check if the $ replacement works with environment variables.'''
     os.environ["huho"] = "ThereIsSomeVal"
     config = Cfg.new_by_json_str('{"k": "${ENV:huho}"}')
     val = config.get_rvalue("k")
     os.environ["huho"] = ""
     assert "ThereIsSomeVal" == val, \
         "k is not ThereIsSomeVal"
开发者ID:florath,项目名称:rmtoo,代码行数:10,代码来源:RMTTest-Configuration.py

示例7: test_json_init_add_old_cmd_line_params

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
    def test_json_init_add_old_cmd_line_params(self):
        '''Init Cfg with JSON and add parameters with command line options'''
        config = Cfg.new_by_json_str('{"k": 1, "l": [2, 3], "m": {"n": 4}}');
        config.merge_cmd_line_params(['-m', '/tmp/something',
                                      '-c', '/tmp/cmad'])

        self.failUnlessEqual(1, config.get_value("k"), "k is not 1")
        self.failUnlessEqual({'create_makefile_dependencies': '/tmp/cmad'},
                             config.get_value("actions").get_dict())
开发者ID:CrypticGator,项目名称:rmtoo,代码行数:11,代码来源:TestConfiguration.py

示例8: rmttest_json_init_add_old_cmd_line_params

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
    def rmttest_json_init_add_old_cmd_line_params(self):
        '''Init Cfg with JSON and add parameters with command line options'''
        config = Cfg.new_by_json_str('{"k": 1, "l": [2, 3], "m": {"n": 4}}')
        config.merge_cmd_line_params(['-m', '/tmp/something',
                                      '-c', '/tmp/cmad'])

        assert 1 == config.get_value("k"), "k is not 1"
        assert {'create_makefile_dependencies': '/tmp/cmad'} == \
            config.get_value("actions")
开发者ID:florath,项目名称:rmtoo,代码行数:11,代码来源:RMTTest-Configuration.py

示例9: test_json_str

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
    def test_json_str(self):
        '''Checks JSON string handling of the configuration class'''
        config = Cfg.new_by_json_str('{"k": 1, "l": [2, 3], "m": {"n": 4}}');
        config.merge_json_str('{"k": 2, "m": {"n": 5}, "o": 7}')

        self.failUnlessEqual(2, config.get_value("k"), "k is not 2")
        self.failUnlessEqual([2, 3], config.get_value("l"), "l is not [2, 3]")
        self.failUnlessEqual(5, config.get_value("m.n"), "m.n is not 5")
        self.failUnlessEqual(5, config.get_value(["m", "n"]), "m.n is not 5")
        self.failUnlessEqual(7, config.get_value("o"), "o is not 7")
开发者ID:CrypticGator,项目名称:rmtoo,代码行数:12,代码来源:TestConfiguration.py

示例10: rmttest_json_str

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
    def rmttest_json_str(self):
        '''Checks JSON string handling of the configuration class'''
        config = Cfg.new_by_json_str('{"k": 1, "l": [2, 3], "m": {"n": 4}}')
        config.merge_json_str('{"k": 2, "m": {"n": 5}, "o": 7}')

        assert 2 == config.get_value("k"), "k is not 2"
        assert [2, 3] == config.get_value("l"), "l is not [2, 3]"
        assert 5 == config.get_value("m.n"), "m.n is not 5"
        assert 5 == config.get_value(["m", "n"]), "m.n is not 5"
        assert 7 == config.get_value("o"), "o is not 7"
开发者ID:florath,项目名称:rmtoo,代码行数:12,代码来源:RMTTest-Configuration.py

示例11: test_neg_06

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
    def test_neg_06(self):
        "TestRecordTxt2: long long line - check for multiple errors"
        mstderr = StringIO.StringIO()
        init_logger(mstderr)

        cfg = Cfg.new_by_json_str('{"max_input_line_length": 7}')
        tioconfig = TxtIOConfig(cfg)
        txt_doc = TxtRecord.from_string("""#1 com
ok: yes
 no
#4 cs
#5 dds
good: but too long
#7 dds
#8 hi
also good: but too long
#10 gsst
 dhd
#12 dhdh 
d:
#14
""",
                                        "TooLong", tioconfig)

        self.assertEqual(txt_doc.is_usable(), False)
        lstderr = hide_timestamp(mstderr.getvalue())
        tear_down_log_handler()
        
        result_expected = "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;" \
        "check_line_length;77; 80:TooLong:6:line too long: is [18], " \
        "max allowed [7]\n" \
        "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;check_line_length;77; 80:" \
        "TooLong:9:line too long: is [23], max allowed [7]\n" \
        "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;check_line_length;77; 80:" \
        "TooLong:10:line too long: is [8], max allowed [7]\n" \
        "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;check_line_length;77; 80:" \
        "TooLong:12:line too long: is [9], max allowed [7]\n" \
        "===DATETIMESTAMP===;rmtoo;INFO;TxtParser;split_next_record;84; 80:" \
        "TooLong:11:Compatibility info: Comments will be reordered when " \
        "they are re-written with rmtoo-tools. Please consult " \
        "rmtoo-req-format(5) or rmtoo-topic-format(5)\n"
        
        self.assertEquals(result_expected, lstderr)
开发者ID:CrypticGator,项目名称:rmtoo,代码行数:45,代码来源:TestRecordTxt2.py

示例12: test_json_init_add_old2_cmd_line_params

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
    def test_json_init_add_old2_cmd_line_params(self):
        '''Init Cfg with old config and adds parameters with command line options'''
        mstderr = StringIO.StringIO()
        init_logger(mstderr)

        config = Cfg.new_by_json_str('{"k": 1, "l": [2, 3], "m": {"n": 4}}');
        config.merge_cmd_line_params(['-f', 'tests/UnitTest/CoreTests/'
                                      'testdata/Config3.py'])

        self.failUnlessEqual(1, config.get_value("k"), "k is not 1")
        config.evaluate()
        self.failUnlessEqual(['development', 'management', 'users', 'customers'],
                             config.get_value("requirements.stakeholders"))
        lstderr = hide_timestamp(mstderr.getvalue())
        tear_down_log_handler()

        expected_result = "===DATETIMESTAMP===;rmtoo;WARNING;Old;" \
        "internal_convert_to_new;171;100:Old Configuration: " \
        "Not converted attributes: [['output_specs2']]\n"

        self.failUnlessEqual(expected_result, lstderr)
开发者ID:CrypticGator,项目名称:rmtoo,代码行数:23,代码来源:TestConfiguration.py

示例13: test_json_init_add_old_cmd_line_params

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
    def test_json_init_add_old_cmd_line_params(self):
        '''Init Cfg with old config and adds parameters with command line options'''
        log_store = MemLogStore()

        config = Cfg.new_by_json_str('{"k": 1, "l": [2, 3], "m": {"n": 4}}');
        config.merge_cmd_line_params(['-f', 'tests/unit-test/core-tests/'
                                      'testdata/Config3.py'])

        self.failUnlessEqual(1, config.get_value("k"), "k is not 1")
        config.evaluate(log_store)
        self.failUnlessEqual(['development', 'management', 'users', 'customers'],
                             config.get_value("requirements.stakeholders"))
        print("UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU")
        log_store.write_log(sys.stdout)

## TODO:+ + +Warning:100:Old Configuration: Not converted attributes: [['output_specs2']]

        print("VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV")
        self.failUnlessEqual(MemLogStore.create_mls([[
            100, LogLevel.warning(),
            "Old Configuration: Not converted attributes: [['output_specs2']]"]]),
                             log_store)
开发者ID:oscarpicas,项目名称:rmtoo,代码行数:24,代码来源:TestConfiguration.py

示例14: test_dollar_replacement_configuration_variables

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
 def test_dollar_replacement_configuration_variables(self):
     '''Check if the $ replacement works with configuration variables.'''
     config = Cfg.new_by_json_str(
         '{"k": "${huho}", "huho": "ThereIsSomeVal"}')
     self.failUnlessEqual("ThereIsSomeVal", config.get_rvalue("k"),
                          "k is not ThereIsSomeVal")
开发者ID:CrypticGator,项目名称:rmtoo,代码行数:8,代码来源:TestConfiguration.py

示例15: rmttest_dollar_replacement_configuration_variables

# 需要导入模块: from rmtoo.lib.configuration.Cfg import Cfg [as 别名]
# 或者: from rmtoo.lib.configuration.Cfg.Cfg import new_by_json_str [as 别名]
 def rmttest_dollar_replacement_configuration_variables(self):
     '''Check if the $ replacement works with configuration variables.'''
     config = Cfg.new_by_json_str(
         '{"k": "${huho}", "huho": "ThereIsSomeVal"}')
     assert "ThereIsSomeVal" == config.get_rvalue("k"), \
         "k is not ThereIsSomeVal"
开发者ID:florath,项目名称:rmtoo,代码行数:8,代码来源:RMTTest-Configuration.py


注:本文中的rmtoo.lib.configuration.Cfg.Cfg.new_by_json_str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。