def test_mysql_load_options_dateformat(self) -> None: expected_failures: Set[str] = { 'MM-DD-YYYY', 'DD-MM-YYYY', 'MM/DD/YY', 'DD/MM/YY', 'DD-MM-YY', } for dateformat in DATE_CASES: records_format = DelimitedRecordsFormat(variant='bluelabs', hints={ 'dateformat': dateformat, 'compression': None, }) unhandled_hints = set(records_format.hints.keys()) try: mysql_load_options(unhandled_hints, records_format, fail_if_cant_handle_hint=True) except NotImplementedError: if dateformat in expected_failures: continue else: raise self.assertNotIn(dateformat, expected_failures)
def test_mysql_load_options_encoding_utf8bom_fail(self) -> None: records_format = DelimitedRecordsFormat(variant='bluelabs', hints={ 'encoding': 'UTF8BOM', 'compression': None, }) unhandled_hints = set(records_format.hints.keys()) with self.assertRaises(NotImplementedError) as r: mysql_load_options(unhandled_hints, records_format, fail_if_cant_handle_hint=True) self.assertIn('UTF8BOM', str(r.exception))
def test_load_known_formats(self): mock_db = Mock(name='db') mock_url_resolver = Mock(name='url_resolver') loader = MySQLLoader(db=mock_db, url_resolver=mock_url_resolver) known_load_formats = loader.known_supported_records_formats_for_load() for records_format in known_load_formats: unhandled_hints = set(records_format.hints) # ensure no exception thrown mysql_load_options(unhandled_hints, records_format, fail_if_cant_handle_hint=True) complain_on_unhandled_hints(fail_if_dont_understand=True, unhandled_hints=unhandled_hints, hints=records_format.hints)
def test_mysql_load_options_valid_quoting_no_doublequote(self) -> None: records_format = DelimitedRecordsFormat(variant='bluelabs', hints={ 'quoting': 'all', 'doublequote': False, 'compression': None, }) unhandled_hints = set(records_format.hints.keys()) with self.assertRaises(NotImplementedError) as r: mysql_load_options(unhandled_hints, records_format, fail_if_cant_handle_hint=True) self.assertIn('doublequote=False', str(r.exception))
def test_mysql_load_options_bogus_quoting(self) -> None: records_format = DelimitedRecordsFormat( variant='bluelabs', hints={ 'quoting': 'no thanks', # type: ignore 'doublequote': True, 'compression': None, }) unhandled_hints = set(records_format.hints.keys()) with self.assertRaises(NotImplementedError) as r: mysql_load_options(unhandled_hints, records_format, fail_if_cant_handle_hint=True) self.assertIn('no thanks', str(r.exception))
def test_mysql_load_options_encoding_utf8bom_fallback(self) -> None: records_format = DelimitedRecordsFormat(variant='bluelabs', hints={ 'encoding': 'UTF8BOM', 'compression': None, }) unhandled_hints = set(records_format.hints.keys()) out = mysql_load_options(unhandled_hints, records_format, fail_if_cant_handle_hint=False) self.assertEqual(out.character_set, 'utf8')
def test_mysql_load_options_nonnumeric_quoting(self) -> None: records_format = DelimitedRecordsFormat(variant='bluelabs', hints={ 'quoting': 'nonnumeric', 'doublequote': True, 'compression': None, }) unhandled_hints = set(records_format.hints.keys()) out = mysql_load_options(unhandled_hints, records_format, fail_if_cant_handle_hint=True) self.assertEqual(out.fields_optionally_enclosed_by, '"')
def test_mysql_load_options_timeonlyformat(self) -> None: expected_failures: Set[str] = { 'HH12:MI AM', } for timeonlyformat in TIMEONLY_CASES: records_format = DelimitedRecordsFormat(variant='bluelabs', hints={ 'timeonlyformat': timeonlyformat, 'compression': None, }) unhandled_hints = set(records_format.hints.keys()) try: mysql_load_options(unhandled_hints, records_format, fail_if_cant_handle_hint=True) except NotImplementedError: if timeonlyformat in expected_failures: continue else: raise self.assertNotIn(timeonlyformat, expected_failures)