def test_load_nonfile(stc): pkg = "spirent.methodology" test_xml = get_test_xml() neg_test_xml = "<xxx/>" with open("TemplateXmlTestFile.xml", "w") as f: f.write(neg_test_xml) assert os.path.isfile("TemplateXmlTestFile.xml") sequencer = CStcSystem.Instance().GetObject("Sequencer") ctor = CScriptableCreator() hnd_reg = CHandleRegistry.Instance() cmd = ctor.Create(pkg + ".LoadTemplateCommand", sequencer) cmd.Set("AutoExpandTemplate", False) LoadCmd.get_this_cmd = MagicMock(return_value=cmd) res = LoadCmd.run( 1, "", test_xml, os.path.join(os.getcwd(), "IncorrectFileName.xml"), "", False, True, 0) # Note carefully the name of the file above is incorrect... assert res is False StmTemplateConfig = hnd_reg.Find(cmd.Get("StmTemplateConfig")) assert StmTemplateConfig is None os.remove("TemplateXmlTestFile.xml") assert not os.path.isfile("TemplateXmlTestFile.xml") return
def test_load_run(stc): pkg = "spirent.methodology" test_xml = get_test_xml() stc_sys = CStcSystem.Instance() project = stc_sys.GetObject("Project") sequencer = CStcSystem.Instance().GetObject("Sequencer") ctor = CScriptableCreator() hnd_reg = CHandleRegistry.Instance() cmd = ctor.Create(pkg + ".LoadTemplateCommand", sequencer) cmd.SetCollection('TargetTagList', ['meports']) LoadCmd.get_this_cmd = MagicMock(return_value=cmd) # Create the tag for the ports... tags = project.GetObject("Tags") tagMePorts = ctor.Create("Tag", tags) tagMePorts.Set("Name", "meports") tags.AddObject(tagMePorts, RelationType("UserTag")) port1 = ctor.Create("Port", project) port1.Set("Location", "//10.14.16.27/2/1") port1.AddObject(tagMePorts, RelationType("UserTag")) res = LoadCmd.run(1, ["meports"], test_xml, "", "", True, False, 0) assert res is True # Verify the StmTemplateConfig object was correctly created... container_hnd = cmd.Get("StmTemplateConfig") assert container_hnd is not 0 container = hnd_reg.Find(container_hnd) assert container is not None assert container.IsTypeOf("StmTemplateConfig") assert container.Get("TemplateXml") == test_xml return
def test_load_file(stc): pkg = "spirent.methodology" test_xml = get_test_xml() with open("TemplateXmlTestFile.xml", "w") as f: f.write(test_xml) assert os.path.isfile("TemplateXmlTestFile.xml") sequencer = CStcSystem.Instance().GetObject("Sequencer") ctor = CScriptableCreator() hnd_reg = CHandleRegistry.Instance() cmd = ctor.Create(pkg + ".LoadTemplateCommand", sequencer) cmd.Set("AutoExpandTemplate", False) LoadCmd.get_this_cmd = MagicMock(return_value=cmd) res = LoadCmd.run( 1, "", "<xxx/>", os.path.join(os.getcwd(), "TemplateXmlTestFile.xml"), "", False, True, 0) assert res is True StmTemplateConfig = hnd_reg.Find(cmd.Get("StmTemplateConfig")) assert StmTemplateConfig is not None xml = StmTemplateConfig.Get("TemplateXml") assert xml == test_xml os.remove("TemplateXmlTestFile.xml") assert not os.path.isfile("TemplateXmlTestFile.xml") return
def test_no_template_source(stc): pkg = "spirent.methodology" test_xml = get_test_xml() stc_sys = CStcSystem.Instance() project = stc_sys.GetObject("Project") sequencer = CStcSystem.Instance().GetObject("Sequencer") ctor = CScriptableCreator() cmd = ctor.Create(pkg + ".LoadTemplateCommand", sequencer) cmd.SetCollection('TargetTagList', ['meports']) LoadCmd.get_this_cmd = MagicMock(return_value=cmd) # Create the tag for the ports... tags = project.GetObject("Tags") tagMePorts = ctor.Create("Tag", tags) tagMePorts.Set("Name", "meports") tags.AddObject(tagMePorts, RelationType("UserTag")) port1 = ctor.Create("Port", project) port1.Set("Location", "//10.14.16.27/2/1") port1.AddObject(tagMePorts, RelationType("UserTag")) res = LoadCmd.run(1, ["meports"], test_xml, "", "", True, True, 0) assert res is False return