def __init__(self, topic_set, params): self.topic_set = topic_set cfg = Cfg(params) self.output_dir = cfg.get_value('output_directory') self.html_header_filename = cfg.get_value('header') self.html_footer_filename = cfg.get_value('footer') self.read_html_arts()
def main_setup_config(args): """Setup the config for main()""" config = Cfg() DefaultValues.set_default_values(config) config.merge_cmd_line_params(args) config.evaluate() return config
def __init__(self, self_cfg, import_dest): tracer.info("called") self.useable = False self._cfg = dict(self.default_config) self._cfg.update(self_cfg) self._dest = dict() self._entries = None self._topics = None import_dest_cfg = Cfg(import_dest) try: req_dirs = import_dest_cfg.get_rvalue("requirements_dirs") if req_dirs[0] and os.path.isdir(req_dirs[0]): self.useable = True self._dest["requirements_dirs"] = req_dirs[0] except RMTException: self.useable = False try: topics_dirs = import_dest_cfg.get_rvalue("topics_dirs") if topics_dirs[0] and os.path.isdir(topics_dirs[0]): self.useable = True self._dest["topics_dirs"] = topics_dirs[0] except RMTException: self.useable = False self._wb = None tracer.debug("Finished.")
def __init__(self, config): cfg = Cfg(config) Interface.__init__(self, cfg) tracer.info("called") self.__topic_root_node = cfg.get_rvalue("topic_root_node") self.__dirs = {} self.__setup_directories(cfg)
def __init__(self, topic_set, params): self.topic_set = topic_set cfg = Cfg(params) self.output_filename = cfg.get_value('output_filename') self.effort_factor = cfg.get_value_default('effort_factor', 1) self.req_ids = {} self.next_id = 1
def __init__(self, config): '''Constructs the standard output parameters based on the provided config.''' self._output_filename = None self._start_date = None self._end_date = None self._config = Cfg(config) self.__parse()
def rmttest_pos_01(self): "TxtIOConfig: check new max line length setting" config = Cfg() config.set_value('max_input_line_length', 77) tic = TxtIOConfig(config, 'requirement') assert(tic.get_max_line_length() == 77)
def test_pos_01(self): "TxtIOConfig: check new max line length setting" config = Cfg() config.set_value('max_input_line_length', 77) tic = TxtIOConfig(config, 'requirement') assert (tic.get_max_line_length() == 77)
def _extract_input_dir(self, config): input_cfg = Cfg(config) sources_dirs = "topics.ts_common.sources" for cfg in input_cfg.get_value(sources_dirs): for req_idx in [ "requirements_dirs", "topics_dirs", "sources_dirs" ]: if req_idx in cfg[1]: self._input_dir[req_idx] = cfg[1][req_idx]
def rmttest_positive_02(self): "TopicSet - valid" cfg = Cfg() cfg.set_value('hahaha.directory', 'tests/unit-test/topic-tests/testdata/topicset01') cfg.set_value('hahaha.name', 't01') cfg.set_value('topics.test-name01.output', {}) cfg.set_value('topic_root_node', 'RootNode') tvcs = TestVCS(cfg) tobjcache = ObjectCache() tinmod = TestInputModules() TopicSet(cfg, tvcs, "test-name01", tobjcache, tinmod)
def __init__(self, oconfig): '''Create a graph output object.''' tracer.debug("Called: html ouput module constructed.") self._config = Cfg(oconfig) CreateMakeDependencies.__init__(self) self.__fd_stack = [] self.__topic_name_set = [] # Take care about the openess of the ul. self.__ul_open_stack = [] self.__output_directory = self._config.get_rvalue('output_directory') self.html_header_filename = self._config.get_rvalue('header') self.html_footer_filename = self._config.get_rvalue('footer') self.read_html_arts()
def test_positive_03(self): "TopicSet - valid with empty requirement set" tioconfig = TxtIOConfig() cfg = Cfg() cfg.set_value('huhuhu.directory', 'tests/unit-test/topic-tests/testdata/topicset01') cfg.set_value('huhuhu.name', 't01') cfg.set_value('topics.test-name02.output', {}) cfg.set_value('topic_root_node', 'RootNode') tvcs = TestVCS(cfg) tobjcache = ObjectCache() tinmod = TestInputModules() topicset = TopicSet(cfg, tvcs, "test-name02", tobjcache, tinmod)
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")
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)
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)
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, "")
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 == ""
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, "")
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)
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 == ""
def rmttest_positive_03(self): "TopicSet - valid with empty requirement set" cfg = Cfg() cfg.set_value('huhuhu.directory', 'tests/unit-test/topic-tests/testdata/topicset01') cfg.set_value('huhuhu.name', 't01') cfg.set_value('topics.test-name02.output', {}) cfg.set_value('topic_root_node', 'RootNode') tvcs = TestVCS(cfg) tobjcache = ObjectCache() tinmod = TestInputModules() TopicSet(cfg, tvcs, "test-name02", tobjcache, tinmod)
def rmttest_positive_01(self): "TopicSet - constructor with only one element" try: cfg = Cfg() cfg.set_value('ahah.directory', 'tests/unit-test/topic-tests/testdata/topicset01') cfg.set_value('ahah.name', 't01') cfg.set_value('topics.bkdkd.output', {}) cfg.set_value('topic_root_node', 'RootNode') tvcs = TestVCS(cfg) tobjcache = ObjectCache() tinmod = TestInputModules() TopicSet(cfg, tvcs, "bkdkd", tobjcache, tinmod) self.assertTrue(False) except AssertionError: pass
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"
def __init__(self, config): tracer.info("called") cfg = Cfg(config) self.__start_vers = cfg.get_value("start_vers") self.__end_vers = cfg.get_value("end_vers") self.__topic_root_node = cfg.get_value("topic_root_node") tracer.debug("start version [%s] end version [%s] " "topic root node [%s]" % (self.__start_vers, self.__end_vers, self.__topic_root_node)) # When the directory is not absolute, convert it to an # absolute path that it can be compared to the outcome of the # git.Repo. self.__dirs = {} self.__repo_base_dir = None self.__repo = None self.__setup_directories(cfg)
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")
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())
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())
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")
def test_positive_02(self): "TopicSet - valid" tioconfig = TxtIOConfig() cfg = Cfg() cfg.set_value('hahaha.directory', 'tests/unit-test/topic-tests/testdata/topicset01') cfg.set_value('hahaha.name', 't01') cfg.set_value('topics.test-name01.output', {}) tioconfig = TxtIOConfig() cfg.set_value('topic_root_node', 'RootNode') tvcs = TestVCS(cfg) tobjcache = ObjectCache() tinmod = TestInputModules() topicset = TopicSet( cfg, tvcs, "test-name01", tobjcache, tinmod)
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")
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"
def __init__(self, config): tracer.info("called") cfg = Cfg(config) Interface.__init__(self, cfg) self.__start_vers = cfg.get_rvalue("start_vers") self.__end_vers = cfg.get_rvalue("end_vers") self.__topic_root_node = cfg.get_rvalue("topic_root_node") tracer.debug( "start version [%s] end version [%s] " "topic root node [%s]" % (self.__start_vers, self.__end_vers, self.__topic_root_node)) # When the directory is not absolute, convert it to an # absolute path that it can be compared to the outcome of the # git.Repo. self.__dirs = {} self.__repo_base_dir = None self.__repo = None self.__setup_directories(cfg)
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")
def test_empty_configuration(self): '''Checks the empty configuration with different types of parameters''' config = Cfg() self.failUnlessRaises(RMTException, config.get_value, "k") self.failUnlessRaises(RMTException, config.get_value, "k.i") self.failUnlessRaises(RMTException, config.get_value, "k.i.j") self.failUnlessRaises(RMTException, config.get_value, ['k']) self.failUnlessRaises(RMTException, config.get_value, ['k', 'i']) self.failUnlessRaises(RMTException, config.get_value, ['k', 'i', 'j'])
def rmttest_positive_01(self): "TopicSet - constructor with only one element" try: cfg = Cfg() cfg.set_value('ahah.directory', 'tests/unit-test/topic-tests/testdata/topicset01') cfg.set_value('ahah.name', 't01') cfg.set_value('topics.bkdkd.output', {}) cfg.set_value('topic_root_node', 'RootNode') tvcs = TestVCS(cfg) tobjcache = ObjectCache() tinmod = TestInputModules() TopicSet(cfg, tvcs, "bkdkd", tobjcache, tinmod) assert False except AssertionError: pass
def test_positive_02(self): "TopicSet - valid" cfg = Cfg() cfg.set_value('hahaha.directory', 'tests/unit-test/topic-tests/testdata/topicset01') cfg.set_value('hahaha.name', 't01') cfg.set_value('topics.test-name01.output', {}) tioconfig = TxtIOConfig() topicset = TopicSet( None, cfg, "test-name01", "hahaha")
class html(ExecutorTopicContinuum, CreateMakeDependencies): def __init__(self, oconfig): '''Create a graph output object.''' tracer.debug("Called: html ouput module constructed.") self._config = Cfg(oconfig) CreateMakeDependencies.__init__(self) self.__fd_stack = [] self.__topic_name_set = [] # Take care about the openess of the ul. self.__ul_open_stack = [] self.__output_directory = self._config.get_rvalue('output_directory') self.html_header_filename = self._config.get_rvalue('header') self.html_footer_filename = self._config.get_rvalue('footer') self.read_html_arts() def __ouput_html_topic_mkdirs(self): '''If not already there, create the directory.''' try: os.makedirs(self.__output_directory) except OSError, ose: # It's ok if already there pass
def test_positive_01(self): "TopicSet - constructor with only one element" try: tioconfig = TxtIOConfig() cfg = Cfg() cfg.set_value('ahah.directory', 'tests/unit-test/topic-tests/testdata/topicset01') cfg.set_value('ahah.name', 't01') cfg.set_value('topics.bkdkd.output', {}) topicset = TopicSet(None, cfg, "bkdkd", "ahah") assert(False) except AssertionError, ae: pass
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)
def test_neg_01(self): "ReqsContinuum: check exception when vcs is needed but not available" try: tdir = tempfile.mkdtemp(prefix="rmtoo-tst-ctnt-") config = Cfg() config.set_value('requirements.input.commit_interval.begin', 'v1') config.set_value('requirements.input.commit_interval.end', 'v7') config.set_value('requirements.input.directory', tdir) ReqsContinuum(None, config) assert(False) except RMTException, rmte: shutil.rmtree(tdir) assert(rmte.id() == 40)
def __init__(self, config): """Sets up Import for use.""" tracer.info("called") self.__plugin_manager = extension.ExtensionManager( namespace="rmtoo.imports.plugin", invoke_on_load=False) assert config # we need a configuration if "import" in config: self._config = config["import"] else: self._config = self.DEFAULT_CONFIG self._cfg = Cfg(self._config) self._input_dir = {"requirements_dirs": None, "topics_dirs": None} self._extract_input_dir(config) self._import_obj = [] self._set_run_modules() tracer.debug("Finished.")
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)
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
class StdOutputParams: '''Handles the standard output parameters and sets the values in the self object provided.''' def __init__(self, config): '''Constructs the standard output parameters based on the provided config.''' self._output_filename = None self._start_date = None self._end_date = None self._config = Cfg(config) self.__parse() def __parse_output_filename(self): '''Sets the output filename.''' self._output_filename = self._config.get_rvalue('output_filename') @staticmethod def __parse_date(cfg, name, default_value): '''If name is in params, the value is converted to a date and returned. If name is not in params, the default_value is returned.''' pname = cfg.get_value_wo_throw(name) if pname == None: return default_value return parse_date(name, pname) def __parse_start_and_end_date(self): '''Extracts the start and the end date from the params.''' today = datetime.date.today() yesterday = today - datetime.timedelta(1) self._start_date = self.__parse_date( self._config, 'start_date', yesterday) tracer.debug("Start date [%s]" % self._start_date) self._end_date = self.__parse_date(self._config, 'end_date', today) tracer.debug("End date [%s]" % self._end_date) def __parse(self): '''Parses the standard parameters.''' self.__parse_output_filename() self.__parse_start_and_end_date()
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)
class StdOutputParams(object): '''Handles the standard output parameters and sets the values in the self object provided.''' def __init__(self, config): '''Constructs the standard output parameters based on the provided config.''' self._output_filename = None self._start_date = None self._end_date = None self._config = Cfg(config) self.__parse() def __parse_output_filename(self): '''Sets the output filename.''' self._output_filename = self._config.get_rvalue('output_filename') @staticmethod def __parse_date(cfg, name, default_value): '''If name is in params, the value is converted to a date and returned. If name is not in params, the default_value is returned.''' pname = cfg.get_value_wo_throw(name) if pname is None: return default_value return parse_date(name, pname) def __parse_start_and_end_date(self): '''Extracts the start and the end date from the params.''' today = datetime.date.today() yesterday = today - datetime.timedelta(1) self._start_date = self.__parse_date(self._config, 'start_date', yesterday) tracer.debug("Start date [%s]", self._start_date) self._end_date = self.__parse_date(self._config, 'end_date', today) tracer.debug("End date [%s]", self._end_date) def __parse(self): '''Parses the standard parameters.''' self.__parse_output_filename() self.__parse_start_and_end_date()
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)
def test_neg_02(self): "ReqsContinuum: check exception when vcs is needed but not available \ (entry point in execute_cmds())" tdir = tempfile.mkdtemp(prefix="rmtoo-tst-ctnt-") config = Cfg() config.set_value('requirements.input.commit_interval.begin', 'v1') config.set_value('requirements.input.commit_interval.end', 'v7') config.set_value('requirements.input.directory', tdir) mstderr = StringIO.StringIO() rval = execute_cmds(config, None, None, mstderr) assert(rval == False) print("ERROR IS [%s]" % mstderr.getvalue()) assert(mstderr.getvalue() == "+++ ERROR: Problem reading in " "the continuum: '[ 40]: Based on the config " "a repository is needed - but there is none'")
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)
def create_parameters(): return Cfg(), {}
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)