def get_row_validators(self, row): """Parses the row validators from the XSD. XSD is either user-specified or inferred from the HEAD row. Args: row: The parsed row from the TSV file. Returns: row_validators_list: A list of subclass of cell_validators.BaseCellValidator. (eg. [[string_validator, decimal_validator],[string_validator]]). """ dsrf_xsd_file = self.dsrf_xsd_file if not dsrf_xsd_file: # User did not specify one, read from the library. profile_name, profile_version = row[2:4] self.logger.info( 'Detected profile and version from HEAD: %s (%s)' % (profile_name, profile_version)) try: dsrf_xsd_file = constants.get_xsd_file(profile_name, profile_version) except ValueError as e: self.logger.error(str(e)) sys.stderr.write(str(e)) sys.exit(-1) self.logger.info('XSD file location: %s' % dsrf_xsd_file) schema_parser = dsrf_schema_parser.DsrfSchemaParser( self.avs_xsd_file, dsrf_xsd_file) return schema_parser.parse_xsd_file(self.logger)
def test_parse_xsd_file_not_exist(self): """Tests a case of xsd file not exist.""" avs_filename = path.join(path.dirname(__file__), '../testdata/avs.xsd') schema_parser = dsrf_schema_parser.DsrfSchemaParser(avs_filename, '') with six.assertRaisesRegex(self, IOError, 'No such file or directory: \'\''): schema_parser.parse_xsd_file(self.logger)
def setUp(self): avs_filename = path.join(path.dirname(__file__), '../testdata/avs.xsd') xsd_filename = path.join(path.dirname(__file__), '../testdata/sales-reporting-flat.xsd') self.dsrf_schema_parser = dsrf_schema_parser.DsrfSchemaParser( avs_filename, xsd_filename) self.logger = dsrf_logger.DSRFLogger(__name__, '/tmp/example.log', True)