Ejemplo n.º 1
0
    def rmttest_neg_05(self):
        "TestRecordTxt2: long long line - check for lineno"
        mstderr = 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_volatile(mstderr.getvalue())
        tear_down_log_handler()

        result_expected \
            = "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;" \
            "check_line_length;===LINENO===; 80:TooLong:6:line too long: " \
            "is [18], max allowed [7]\n"
        self.assertEquals(result_expected, lstderr)
Ejemplo n.º 2
0
    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, "")
Ejemplo n.º 3
0
    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, "")
Ejemplo n.º 4
0
    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 == ""
Ejemplo n.º 5
0
 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")
Ejemplo n.º 6
0
    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 == ""
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
 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"
Ejemplo n.º 10
0
 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"
Ejemplo n.º 11
0
 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")
Ejemplo n.º 12
0
    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")
Ejemplo n.º 13
0
    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")
Ejemplo n.º 14
0
    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())
Ejemplo n.º 15
0
    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())
Ejemplo n.º 16
0
    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")
Ejemplo n.º 17
0
    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"
Ejemplo n.º 18
0
    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"
Ejemplo n.º 19
0
    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")
Ejemplo n.º 20
0
    def rmttest_neg_06(self):
        "TestRecordTxt2: long long line - check for multiple errors"
        mstderr = 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_volatile(mstderr.getvalue())
        tear_down_log_handler()

        result_expected \
            = "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;" \
            "check_line_length;===LINENO===; 80:TooLong:6:line too long: " \
            "is [18], max allowed [7]\n" \
            "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;check_line_length;" \
            "===LINENO===; 80:" \
            "TooLong:9:line too long: is [23], max allowed [7]\n" \
            "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;check_line_length;" \
            "===LINENO===; 80:" \
            "TooLong:10:line too long: is [8], max allowed [7]\n" \
            "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;check_line_length;" \
            "===LINENO===; 80:" \
            "TooLong:12:line too long: is [8], max allowed [7]\n" \
            "===DATETIMESTAMP===;rmtoo;INFO;TxtParser;split_next_record;" \
            "===LINENO===; 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)
Ejemplo n.º 21
0
    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)
Ejemplo n.º 22
0
    def test_neg_04(self):
        "TestRecordTxt2: long long line"
        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("good: but too long", "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:1:line too long: is [18], " \
        "max allowed [7]\n"
        self.assertEquals(result_expected, lstderr)
    def rmttest_neg_04(self):
        "TestRecordTxt2: long long line"
        mstderr = StringIO()
        init_logger(mstderr)

        cfg = Cfg.new_by_json_str('{"max_input_line_length": 7}')

        tioconfig = TxtIOConfig(cfg)
        txt_doc = TxtRecord.from_string("good: but too long", "TooLong",
                                        tioconfig)

        assert txt_doc.is_usable() is False
        lstderr = hide_volatile(mstderr.getvalue())
        tear_down_log_handler()

        result_expected \
            = "===DATETIMESTAMP===;rmtoo;ERROR;TxtRecord;" \
            "check_line_length;===LINENO===; 80:TooLong:1:line too long: " \
            "is [18], max allowed [7]\n"
        assert result_expected == lstderr
Ejemplo n.º 24
0
    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)
Ejemplo n.º 25
0
    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)
Ejemplo n.º 26
0
    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)
Ejemplo n.º 27
0
Archivo: graph.py Proyecto: kown7/rmtoo
class graph(StdOutputParams, ExecutorTopicContinuum, CreateMakeDependencies):
    default_config = Cfg.new_by_json_str("""json:{"node_attributes":
               ["Type", "Status", "Class", "Topic", "Priority" ] }""")

    def __init__(self, oconfig):
        '''Create a graph output object.'''
        tracer.info("Called.")
        StdOutputParams.__init__(self, oconfig)
        CreateMakeDependencies.__init__(self)
        self.__used_vcs_id = None
        self.__output_file = None

        if not self._config.is_available('node_attributes'):
            self._config.set_value('node_attributes', [
                "Type",
                "Status",
                "Class",
                "Topic",
                "Priority",
            ])

    def topic_continuum_sort(self, vcs_commit_ids, topic_sets):
        '''Because graph2 can only one topic continuum,
           the latest (newest) is used.'''
        self.__used_vcs_id = vcs_commit_ids[-1]
        return [topic_sets[vcs_commit_ids[-1].get_commit()]]

    def topic_set_pre(self, _requirement_set):
        '''This is call in the RequirementSet pre-phase.'''
        tracer.debug("Called")
        # Initialize the graph output
        self.__output_file = open(self._output_filename, "w")
        self.__output_file.write(
            "digraph reqdeps {\nrankdir=BT;\nmclimit=10.0;\n"
            "nslimit=10.0;ranksep=1;\n")

    def requirement_set_sort(self, list_to_sort):
        '''Sort by id.'''
        return sorted(list_to_sort, key=lambda r: r.get_id())

    def topic_set_post(self, _requirement_set):
        '''Write footer - close file.'''
        # Print out a node with the version number:
        self.__output_file.write(
            'ReqVersion [shape=plaintext label="ReqVersion\\n%s"]\n' %
            self.__used_vcs_id)
        self.__output_file.write("}\n")
        self.__output_file.close()

    def requirement(self, requirement):
        '''Output the given requirement.'''
        self.__output_file.write(
            '"%s" [%s];\n' % (requirement.get_id(),
                              self.node_attributes(requirement, self._config)))

        for d in requirement.incoming:
            self.__output_file.write('"%s" -> "%s";\n' %
                                     (requirement.get_id(), d.get_id()))

# TODO: currently the =default_config is needed for graph2

    @staticmethod
    def node_attributes(req, config=default_config):
        def get_conf_attr(attr):
            return config.is_available("node_attributes") \
                and attr in config.get_value("node_attributes")

        # Colorize the current requirement depending on type
        nodeparam = []
        if get_conf_attr("Type") \
                and req.get_value("Type") \
                == RequirementType.initial_requirement:
            nodeparam.append("color=orange")
        if get_conf_attr("Type") \
                and req.get_value("Type") == RequirementType.design_decision:
            nodeparam.append("color=green")

        if get_conf_attr("Status"):
            req_status = req.get_value("Status")

            if isinstance(req_status, RequirementStatusNotDone):
                nodeparam.append("fontcolor=red")
            elif isinstance(req_status, RequirementStatusAssigned):
                nodeparam.append("fontcolor=blue")

            label = 'label="%s' % req.get_id().replace("/", "\\n/")

            if get_conf_attr("Priority"):
                label += "\\n[%4.2f]" % (req.get_value("Priority") * 10)

            if get_conf_attr("EffortEstimation"):
                est_effort = req.get_value("Effort estimation")
                if est_effort is not None:
                    label += "\\n(%d EfEU)" % est_effort

            label += '"'
            nodeparam.append(label)

        if get_conf_attr("Class"):
            rclass = req.get_value("Class")
            if isinstance(rclass, ClassTypeImplementable):
                nodeparam.append("shape=octagon")
            elif isinstance(rclass, ClassTypeSelected):
                nodeparam.append("shape=box")

        return ",".join(nodeparam)

    def cmad_topic_continuum_pre(self, _):
        '''Write out the one and only dependency to all the requirements.'''
        tracer.debug("Called.")
        CreateMakeDependencies.write_reqs_dep(self._cmad_file,
                                              self._output_filename)
Ejemplo n.º 28
0
 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"
Ejemplo n.º 29
0
 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")
Ejemplo n.º 30
0
 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"
Ejemplo n.º 31
0
 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")