def test00LoadProfiles(self): """Function load_profiles.""" print('\nChecking load_profiles...') result = checker_generic.type_check_simple(cf.load_profiles, [self.sample_file], tuple) self.assertTrue(result[0], result[1]) error_message = checker_generic.type_error_message( 'load_profiles', 'Tuple[Dict[str, List[str]], Dict[str, List[str]]]', result) self.assertTrue(isinstance(result[1], tuple), error_message) self.assertTrue( len(result[1]) == 2, "load_profiles should return a 2-item tuple") self._is_dict_of_Ks_to_list_Vs( result[1][0], str, str, 'load_profiles should return a 2-item tuple, and the first item' ' should be of type Dict[str, List[str]]') self._is_dict_of_Ks_to_list_Vs( result[1][1], str, str, 'load_profiles should return a 2-item tuple, and the second item' ' should be of type Dict[str, List[str]]') print(' check complete')
def test_01_extract_phonemes(self): """Function extract_phonemes. """ dictionary = {'YES': ['Y', 'EH1', 'S'], 'NO': ['N', 'OW1']} result = poetry_functions.extract_phonemes([['YES'], ['NO', 'YES']], dictionary) error_message = checker_generic.type_error_message( 'extract_phonemes', 'POEM_PRONUNCIATION', str(result)) self._is_poem_pronunciation(result, error_message)
def test_07_read_poetry_form_descriptions(self): """Function read_poetry_form_descriptions. """ result = poetry_reader.read_poetry_form_descriptions( self.poetry_form_file) error_message = checker_generic.type_error_message( 'read_poetry_form_descriptions', 'POETRY_FORM', str(result)) self._is_poetry_form_description(result, error_message)
def test_06_read_pronouncing_dictionary(self): """Function read_pronouncing_dictionary. """ result = poetry_reader.read_pronouncing_dictionary( self.dictionary_file) error_message = checker_generic.type_error_message( 'read_pronouncing_dictionary', 'PRONOUNCING_DICTIONARY', str(result)) self._is_pronouncing_dictionary(result, error_message)
def test_04_get_num_syllables(self): """Function get_num_syllables. """ result = poetry_functions.get_num_syllables([[['S', 'IH0', 'N']]]) error_message = checker_generic.type_error_message( 'get_num_syllables', 'List[int]', str(result)) self.assertIsInstance(result, list, error_message) for value in result: self.assertIsInstance(value, int, error_message)
def test_03_get_rhyme_scheme(self): """Function get_rhyme_scheme. """ result = poetry_functions.get_rhyme_scheme([[['IH0', 'N']], [['S', 'IH0', 'N']]]) error_message = checker_generic.type_error_message( 'get_rhyme_scheme', 'List[str]', str(result)) self.assertIsInstance(result, list, error_message) for value in result: self.assertIsInstance(value, str, error_message)
def _returns_list_of_n_ints(self, func: callable, args: list, n: int): """Check that func(args) returns a list of n ints.""" print('\nChecking {}...'.format(func.__name__)) result = checker_generic.returns_list_of_Ts(func, args, int) self.assertTrue(result[0], result[1]) msg = checker_generic.type_error_message( func.__name__, 'list of {} ints'.format(n), result[1]) self.assertTrue(len(result[1]) == n, msg) for i in range(n): self.assertTrue(isinstance(result[1][i], int), msg) print(' check complete')
def test03InvertAndSort(self): """Function invert_and_sort.""" print('\nChecking invert_and_sort...') result = cf.invert_and_sort(self.p2c) error_message = checker_generic.type_error_message( 'invert_and_sort', 'Dict[object, list]', type(result)) self.assertTrue(isinstance(result, dict), error_message) for key in result: self.assertTrue( isinstance(result[key], list), 'invert_and_sort returns a dict, ' 'but the one or more value(s) is not of type list') print(' check complete')
def test07GetLowerResolution(self): """Function get_lower_resolution""" result = checker_generic.returns_list_of_Ts( elevation.get_lower_resolution, [[[1, 3, 4, 2], [2, 1, 1, 2], [4, 1, 1, 4], [3, 2, 1, 4]]], list) self.assertTrue(result[0], result[1]) self.assertTrue(result[1] != [], 'get_lower_resolution should return a non-empty list') msg = checker_generic.type_error_message('get_lower_resolution', 'List[List[int]]', result[1]) for sublist in result[1]: self.assertTrue( sublist != [], 'get_lower_resolution should return a list of non-empty list') self.assertTrue( checker_generic.returns_list_of_Ts(lambda x: x, [sublist], int)[0], msg)