def test_1(self, **param): """Test cross-multiply data-driven""" l = param['left'] r = param['right'] logger.info('%d x %d = %d' % (l, r, l*r)) print('[thread:%d] Bob test multiply' % threading.current_thread().ident) time.sleep(1)
def add_globals(self): cab_msd_globals = self.cab_msd_tree.xpath('/VODML/GLOBALS') param_globals = self.param_tree.xpath('/VODML/GLOBALS') for global_ele in self._get_unique_element( param_globals).getchildren(): logger.info("Adding globals ID=%s", global_ele.attrib["ID"]) self._get_unique_element(cab_msd_globals).append(global_ele)
def _populate_instance(self): self._instancier = Instancier(self.votable_path, json_inst_dict=self.json_vodml_block) self._instancier.set_element_values() self._instancier.set_array_values() self._instancier.map_columns() logger.info("VODML instance created")
def test_1(self): for i in range(3): logger.info('Here is log #%d of test_1' % i) print('[thread:%d] Mary test 1==1 (%d)' % (threading.current_thread().ident, i + 1)) self.assertEqual(1, 1) time.sleep(1)
def test_exclude_methods_from_module(self): dict_conf = { "suites": { "my_suite_1": { "package": "tests.mock1", "groups": { "g1": { "disable": False, "granularity": "module", "modules": ["test_module1"], "except_methods": ["test_module1.MyTestClass1.test_1", "test_module1.MyTestClass2.test_3"], } }, } }, "test": {"suites": ["my_suite_1"]}, } suite_dict = self.loader.load_tests_from_dict(dict_conf) loader = unittest.TestLoader() exp_suite = unittest.TestSuite() exp_suite.addTest( loader.loadTestsFromNames(["MyTestClass1.test_2", "MyTestClass2.test_4"], module=test_module1) ) logger.info(suite_dict["my_suite_1"]["suite"]) self.assertEqual(suite_dict["my_suite_1"]["suite"].countTestCases(), exp_suite.countTestCases())
def test_load_modules(self): dict_conf = { 'suites': { 'my_suite_1': { 'package': 'tests.mock1', 'groups': { 'g1': { 'disable': False, 'granularity': 'module', 'modules': ['test_module1', 'test_module2'] } } } }, 'test': { 'suites': ['my_suite_1'] } } suite_dict = self.loader.load_tests_from_dict(dict_conf) self.assertEqual(suite_dict['my_suite_1']['package'], 'tests.mock1') loader = unittest.TestLoader() exp_suite = unittest.TestSuite() exp_suite.addTests(list(map(loader.loadTestsFromModule, [test_module1, test_module2]))) logger.info(suite_dict['my_suite_1']['suite']) self.assertEqual(suite_dict['my_suite_1']['suite'].countTestCases(), exp_suite.countTestCases())
def test_exclude_classes(self): dict_conf = { 'suites': { 'my_suite_1': { 'package': 'tests.mock1', 'groups': { 'g1': { 'disable': False, 'granularity': 'module', 'modules': ['test_module1', 'test_module2'], 'except_classes': ['test_module1.MyTestClass1', 'test_module2.MyTestClass3'] } } } }, 'test': { 'suites': ['my_suite_1'] } } suite_dict = self.loader.load_tests_from_dict(dict_conf) loader = unittest.TestLoader() exp_suite = unittest.TestSuite() exp_suite.addTest(loader.loadTestsFromName('MyTestClass2', module=test_module1)) exp_suite.addTest(loader.loadTestsFromName('MyTestClass4', module=test_module2)) logger.info(suite_dict['my_suite_1']['suite']) self.assertEqual(suite_dict['my_suite_1']['suite'].countTestCases(), exp_suite.countTestCases())
def set_notset_value(self): notset_values = self.cab_msd_tree.xpath("//VALUE[@ref='@@@@@@']") for notset_value in notset_values: logger.info("Set value of tag %s as NotSet", notset_value.attrib["dmrole"]) notset_value.attrib["value"] = "NoSet" if "ref" in notset_value.attrib.keys(): notset_value.attrib.pop("ref")
def _validate_vodml_block(self): base_path = os.path.dirname(os.path.realpath(__file__)) validator = Validator( os.path.join(base_path, "../../schema/", "vodml_lite.xsd")) validator.validate_string(self.vodml_block) logger.info("VODML block is valid") self.json_block = xmltodict.parse(self.vodml_block)
def test_1(self, **param): """Test cross-multiply data-driven""" l = param['left'] r = param['right'] logger.info('%d x %d = %d' % (l, r, l * r)) print('[thread:%d] Bob test %dx%d' % (threading.current_thread().ident, l, r)) time.sleep(1)
def _extract_vodml_block(self): with open(self.votable_path) as xml_file: self.vodml_block = re.search(r'<VODML>((.|\n)*?)</VODML>', xml_file.read()).group() if self.vodml_block is None: raise Exception("No vodml block found") logger.info("VODML found")
def save(self, filepath): logger.info("save mapping bloc in %s", filepath) self._clean_tree() with open(filepath, 'wb') as output_file: etree.ElementTree(self.cab_msd_clean_tree).write( output_file, encoding="utf-8", xml_declaration=False, pretty_print=True)
def set_ref(self, host_role, value_role, value_ref): block = self._get_unique_element( self.cab_msd_tree.xpath("//INSTANCE[@dmrole='" + host_role + "']")) value_block = self._get_unique_element( block.xpath(".//VALUE[@dmrole='" + value_role + "']")) logger.info("Set ref of %s[%s] = %s", host_role, value_role, value_ref) value_block.attrib["ref"] = value_ref if "value" in value_block.attrib.keys(): value_block.attrib.pop("value")
def set_value(self, host_role, value_role, value_value): block = self._get_unique_element( self.cab_msd_tree.xpath("//INSTANCE[@dmrole='" + host_role + "']")) if "ref" in block.attrib.keys(): block = self._get_global_instance(block.attrib["ref"]) value_block = self._get_unique_element( block.xpath(".//VALUE[@dmrole='" + value_role + "']")) logger.info("Set value of %s[%s] = %s", host_role, value_role, value_value) value_block.attrib["value"] = value_value if "ref" in value_block.attrib.keys(): value_block.attrib.pop("ref")
def add_param_parameter(self): parameters_block = self._get_unique_element( self.cab_msd_tree.xpath( "//COMPOSITION[@dmrole='cab_msd:Source.parameters']")) param_block = self._get_unique_element( self.param_tree.xpath("//INSTANCE[@dmrole='root']")) logger.info("Adding parameter dmtype=%s", param_block.attrib["dmtype"]) new_param = etree.fromstring(self.param_template) param_block = deepcopy(param_block) param_block.attrib["dmrole"] = "cab_msd:Parameter.measure" new_param.append(param_block) parameters_block.append(new_param)
def test_load_non_existing_class(self): dict_conf = { "suites": { "my_suite_1": { "package": "tests.mock1", "groups": { "g1": {"disable": False, "granularity": "class", "classes": ["test_module1.MyTestClass5"]} }, } }, "test": {"suites": ["my_suite_1"]}, } suite_dict = self.loader.load_tests_from_dict(dict_conf) logger.info(suite_dict["my_suite_1"]["suite"]) self.assertEqual(suite_dict["my_suite_1"]["suite"].countTestCases(), 0)
def __init__(self, param_template, cab_msd_path, param_path): ''' Constructor ''' self.param_template = param_template self.cab_msd_path = cab_msd_path logger.info("parse %s", self.cab_msd_path) self.cab_msd_tree = etree.parse(self.cab_msd_path) self.param_path = param_path logger.info("parse %s", self.param_path) self.param_tree = etree.parse(self.param_path) self.cab_msd_clean_tree = None
def test_simple(self): """ python -m unittest tests.test_logging.LoggingTest.test_simple DEFAULT_FORMAT = '%(color)s[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d]%(end_color)s %(message)s' DEFAULT_DATE_FORMAT = '%y%m%d %H:%M:%S' class logging.Formatter(fmt=None, datefmt=None, style='%')¶ """ # formatter = logging.Formatter('[%(levelname)1.1s %(asctime)s %(module)s:%(lineno)d] %(message)s', # '%Y-%m-%d %H:%M:%S'); # self.configure_logger('org.allnix.log') #logger = logging.getLogger('default') #logger.setLevel(logging.DEBUG) #logzero.formatter(formatter) #logzero.log #self.logger.warning('My first log') logger.info('My first log')
def test_load_multi_suites_and_groups(self): dict_conf = { 'suites': { 'my_suite_1': { 'package': 'tests.mock1', 'groups': { 'g1': { 'granularity': 'class', 'classes': ['test_module2.MyTestClass3'], 'except_methods': ['test_module2.MyTestClass3.test_5'] }, 'g2': { 'granularity': 'module', 'modules': ['test_module1'], 'except_classes': ['test_module1.MyTestClass2'], 'except_methods': ['test_module1.MyTestClass1.test_2'] } } }, 'my_suite_2': { 'package': 'tests.mock2', 'groups': { 'g1': { 'granularity': 'method', 'methods': ['test_module3.MyTestClass5.test_11', 'test_module3.MyTestClass6.test_13'] } } } }, 'test': { 'suites': ['my_suite_1', 'my_suite_2'] } } suite_dict = self.loader.load_tests_from_dict(dict_conf) loader = unittest.TestLoader() exp_suite1 = unittest.TestSuite() exp_suite1.addTest(loader.loadTestsFromName('MyTestClass1.test_1', module=test_module1)) exp_suite1.addTest(loader.loadTestsFromName('MyTestClass3.test_6', module=test_module2)) exp_suite1.addTest(loader.loadTestsFromName('MyTestClass3.test_7', module=test_module2)) logger.info(suite_dict['my_suite_1']['suite']) self.assertEqual(suite_dict['my_suite_1']['suite'].countTestCases(), exp_suite1.countTestCases()) exp_suite2 = unittest.TestSuite() exp_suite2.addTest(loader.loadTestsFromName('MyTestClass5.test_11', module=test_module3)) exp_suite2.addTest(loader.loadTestsFromName('MyTestClass6.test_13', module=test_module3)) logger.info(suite_dict['my_suite_2']['suite']) self.assertEqual(suite_dict['my_suite_2']['suite'].countTestCases(), exp_suite2.countTestCases())
def test_load_multi_suites_and_groups(self): dict_conf = { "suites": { "my_suite_1": { "package": "tests.mock1", "groups": { "g1": { "granularity": "class", "classes": ["test_module2.MyTestClass3"], "except_methods": ["test_module2.MyTestClass3.test_5"], }, "g2": { "granularity": "module", "modules": ["test_module1"], "except_classes": ["test_module1.MyTestClass2"], "except_methods": ["test_module1.MyTestClass1.test_2"], }, }, }, "my_suite_2": { "package": "tests.mock2", "groups": { "g1": { "granularity": "method", "methods": ["test_module3.MyTestClass5.test_11", "test_module3.MyTestClass6.test_13"], } }, }, }, "test": {"suites": ["my_suite_1", "my_suite_2"]}, } suite_dict = self.loader.load_tests_from_dict(dict_conf) loader = unittest.TestLoader() exp_suite1 = unittest.TestSuite() exp_suite1.addTest(loader.loadTestsFromName("MyTestClass1.test_1", module=test_module1)) exp_suite1.addTest(loader.loadTestsFromName("MyTestClass3.test_6", module=test_module2)) exp_suite1.addTest(loader.loadTestsFromName("MyTestClass3.test_7", module=test_module2)) logger.info(suite_dict["my_suite_1"]["suite"]) self.assertEqual(suite_dict["my_suite_1"]["suite"].countTestCases(), exp_suite1.countTestCases()) exp_suite2 = unittest.TestSuite() exp_suite2.addTest(loader.loadTestsFromName("MyTestClass5.test_11", module=test_module3)) exp_suite2.addTest(loader.loadTestsFromName("MyTestClass6.test_13", module=test_module3)) logger.info(suite_dict["my_suite_2"]["suite"]) self.assertEqual(suite_dict["my_suite_2"]["suite"].countTestCases(), exp_suite2.countTestCases())
def test_load_methods(self): dict_conf = { "suites": { "my_suite_1": { "package": "tests.mock1", "groups": { "g1": { "disable": False, "granularity": "method", "methods": ["test_module1.MyTestClass1.test_1", "test_module2.MyTestClass3.test_5"], } }, } }, "test": {"suites": ["my_suite_1"]}, } suite_dict = self.loader.load_tests_from_dict(dict_conf) logger.info(suite_dict["my_suite_1"]["suite"]) self.assertEqual(suite_dict["my_suite_1"]["suite"].countTestCases(), 2)
def test_load_modules(self): dict_conf = { "suites": { "my_suite_1": { "package": "tests.mock1", "groups": { "g1": {"disable": False, "granularity": "module", "modules": ["test_module1", "test_module2"]} }, } }, "test": {"suites": ["my_suite_1"]}, } suite_dict = self.loader.load_tests_from_dict(dict_conf) self.assertEqual(suite_dict["my_suite_1"]["package"], "tests.mock1") loader = unittest.TestLoader() exp_suite = unittest.TestSuite() exp_suite.addTests(list(map(loader.loadTestsFromModule, [test_module1, test_module2]))) logger.info(suite_dict["my_suite_1"]["suite"]) self.assertEqual(suite_dict["my_suite_1"]["suite"].countTestCases(), exp_suite.countTestCases())
def test_load_non_existing_class(self): dict_conf = { 'suites': { 'my_suite_1': { 'package': 'tests.mock1', 'groups': { 'g1': { 'disable': False, 'granularity': 'class', 'classes': ['test_module1.MyTestClass5'] } } } }, 'test': { 'suites': ['my_suite_1'] } } suite_dict = self.loader.load_tests_from_dict(dict_conf) logger.info(suite_dict['my_suite_1']['suite']) self.assertEqual(suite_dict['my_suite_1']['suite'].countTestCases(), 0)
def test_load_methods(self): dict_conf = { 'suites': { 'my_suite_1': { 'package': 'tests.mock1', 'groups': { 'g1': { 'disable': False, 'granularity': 'method', 'methods': ['test_module1.MyTestClass1.test_1', 'test_module2.MyTestClass3.test_5'] } } } }, 'test': { 'suites': ['my_suite_1'] } } suite_dict = self.loader.load_tests_from_dict(dict_conf) logger.info(suite_dict['my_suite_1']['suite']) self.assertEqual(suite_dict['my_suite_1']['suite'].countTestCases(), 2)
def _build_instance(self): builder = Builder(json_dict=self.json_block) builder.revert_sets("GLOBALS", default_key='globals') #self.builder.revert_compositions("COMPOSITION") builder.revert_sets("TEMPLATES", default_key='root') builder.revert_array() builder.revert_compositions("COMPOSITION") builder.revert_elements("INSTANCE") builder.revert_elements("VALUE") builder.revert_elements("MODEL") """ builder.revert_compositions("COMPOSITION") builder.revert_compositions("TEMPLATES" , default_key='root') builder.revert_array() builder.revert_elements("INSTANCE") builder.revert_elements("VALUE") builder.revert_elements("MODEL") """ self.json_vodml_block = builder.json logger.info("JSON VODML block built")
def test_load_classes(self): dict_conf = { "suites": { "my_suite_1": { "package": "tests.mock1", "groups": { "g1": { "disable": False, "granularity": "class", "classes": ["test_module1.MyTestClass1", "test_module2.MyTestClass3"], } }, } }, "test": {"suites": ["my_suite_1"]}, } suite_dict = self.loader.load_tests_from_dict(dict_conf) loader = unittest.TestLoader() exp_suite = unittest.TestSuite() exp_suite.addTest(loader.loadTestsFromName("MyTestClass1", module=test_module1)) exp_suite.addTest(loader.loadTestsFromName("MyTestClass3", module=test_module2)) logger.info(suite_dict["my_suite_1"]["suite"]) self.assertEqual(suite_dict["my_suite_1"]["suite"].countTestCases(), exp_suite.countTestCases())
def set_param_semantic(self, ucd, semantic): logger.info("set ucd=%s and semantic=%s", ucd, semantic) self.set_value("cab_msd:Source.parameters", "cab_msd:Parameter.ucd", ucd) self.set_value("cab_msd:Source.parameters", "cab_msd:Parameter.semantic", semantic)
def test_2(self): logger.info('Here is log of test_2') print('[thread:%d] Mary test 2!=1' % threading.current_thread().ident) time.sleep(1) self.assertEqual(2, 1)
def test_3(self): logger.info('Here is log of test_3') print('[thread:%d] Bob test 3!=2' % threading.current_thread().ident) time.sleep(1) self.assertEqual(3, 2)
def test_expected_failures(self): logger.info('Passed (expected failure).') self.assertTrue(False)
def test_1(self): for i in range(3): logger.info('Here is log #%d of test_1' % i) print('[thread:%d] Mary test 1==1' % threading.current_thread().ident) self.assertEqual(1, 1) time.sleep(1)
from mapper.votable_merger import VOTableMerger from tests import logger if __name__ == '__main__': base_path = os.path.dirname(os.path.realpath(__file__)) raw_votable_path = os.path.join(base_path, "../../", "data/raw_data", "xmm_detections.xml") annot_votable_path = os.path.join(base_path, "../../", "data/annotated_data", "xmm_detections.annot.xml") cab_msd_path = os.path.join(base_path, "../../", "data/mapping_components", "cab_msd.mapping.xml") position_path = os.path.join(base_path, "../../", "data/mapping_components", "position.mapping.xml") output_mapping_path = os.path.join(base_path, "../../", "data/annotated_data", "xmm_detections.mapping.xml") with open(base_path + '/xmm.config.json') as json_file: data = json.load(json_file) for measure in data["parameters"]: if measure["measure"] == "position": logger.info("Position found") appender = PositionAppender(cab_msd_path, position_path) appender.append_measure(measure) print(appender.tostring()) appender.save(output_mapping_path)
"4xmm_detections.mapping.xml") with open(data_dir + '/product_configs/4xmm.mango.config.json') as json_file: data = json.load(json_file) appender = IdentifierAppender(mango_path) appender.append_measure(data) appender.save(output_mapping_path) for measure in data["parameters"]: appender = None if measure["measure"] == "LonLatSkyPosition": logger.info("Position found") appender = PositionAppender(output_mapping_path, component_path) elif measure["measure"] == "status": logger.info("Status found") appender = StatusAppender(output_mapping_path, component_path) elif measure["measure"] == "Photometry": logger.info("Photometry found") appender = PhotometryAppender(output_mapping_path, component_path) elif measure["measure"] == "GenericMeasure": logger.info("GenericMeasure found") appender = GenericAppender(output_mapping_path, component_path) elif measure["measure"] == "HardnessRatio": logger.info("GenericMeasure found") appender = HardnessRatioAppender(output_mapping_path, component_path) elif measure["measure"] == "DetectionFlag":
def test_successes(self): """This is doc string.""" self.assertEqual(1, 1) logger.info(u'{\n\t"\u6c49": "<~!@#$%^&*()_+=-?/>,;."\n}')
data_dir, "mapping_components", "position.mapping.xml") status_path = os.path.join( data_dir, "mapping_components", "status.mapping.xml") output_mapping_path = os.path.join( data_dir, "annotated_data", "xmm_detections.mapping.xml") with open(data_dir + '/product_configs/xmm.config.json') as json_file: data = json.load(json_file) for measure in data["parameters"]: if measure["measure"] == "position": logger.info("Position found") appender = PositionAppender(cab_msd_path, position_path) appender.append_measure(measure) #print(appender.tostring()) appender.save(output_mapping_path) elif measure["measure"] == "status": logger.info("Status found") appender = StatusAppender(output_mapping_path, status_path) appender.append_measure(measure) #print(appender.tostring()) appender.save(output_mapping_path) merger = VOTableMerger(raw_votable_path, output_mapping_path, annot_votable_path) merger.insert_mapping()
def test_expected_failures(self): logger.info("Passed (expected failure).") self.assertTrue(False)