def test_add_values_to_attribute_of_vocables(self): xml_parser = XMLParser() list_of_words = ["你", "好", "吗", "我", "很"] test_word_list_file_path = self.create_test_words_file(list_of_words) test_vocable_file_path = self.create_test_vocables_file() xsd_file_path = self.project_directory + "res/xld-vocables-schema.xsd" # TODO: check if the chapter is not in the vocables already # attribute value hasn't been added yet, so it should not already be in the vocables # this assertion is necessary to check if the add_values_to_attribute_of_vocables really changes something xml_root = xml_parser.get_xml_element_tree_root(xsd_file_path, test_vocable_file_path) for vocable in xml_root: vocable_word_attribute_text = vocable.find(self.words_attribute_name).text # is this vocable one of the world list? if WordListHelper.is_in_list( WordListHelper, vocable_word_attribute_text, list_of_words, allow_whitespace_characters=True ): print(vocable_word_attribute_text, "is in word list") attribute_text = vocable.find(self.attribute_name).text # does this vocable have the added attribute value? regex = "\s*" + self.attribute_value + "\s*$" print("regex:", regex) print("attribute_text:", attribute_text) assert re.search(regex, attribute_text) is None, ( "attribute value has already added to vocable " + vocable.find(self.words_attribute_name).text ) # now add the attribute value xld_attribute_adder = XLDAttributeAdder(test_vocable_file_path, xsd_file_path, test_word_list_file_path) xld_attribute_adder.add_values_to_attribute_of_vocables( self.attribute_name, self.attribute_value, self.words_attribute_name ) VocableFileWriter.write(VocableFileWriter, xsd_file_path, test_vocable_file_path, xld_attribute_adder.xml_root) # check the vocables again, to see if something has been added xml_root = xml_parser.get_xml_element_tree_root(xsd_file_path, test_vocable_file_path) for vocable in xml_root: vocable_word_attribute_text = vocable.find(self.words_attribute_name).text # is this vocable one of the world list? if WordListHelper.is_in_list( WordListHelper, vocable_word_attribute_text, list_of_words, allow_whitespace_characters=True ): print(vocable_word_attribute_text, "is in word list") attribute_text = vocable.find(self.attribute_name).text # does this vocable have the added attribute value? regex = "\s*" + self.attribute_value + "\s*$" print("regex:", regex) print("attribute_text:", attribute_text) assert re.search(regex, attribute_text) is not None, ( "attribute value has not been added to vocable " + vocable.find(self.words_attribute_name).text )
def test_add_values_to_attribute_of_vocables (self): xml_parser = XMLParser() list_of_words = ['你','好','吗','我','很'] test_word_list_file_path = self.create_test_words_file(list_of_words) test_vocable_file_path = self.create_test_vocables_file() xsd_file_path = self.project_directory + 'res/xld-vocables-schema.xsd' # TODO: check if the chapter is not in the vocables already # attribute value hasn't been added yet, so it should not already be in the vocables # this assertion is necessary to check if the add_values_to_attribute_of_vocables really changes something xml_root = xml_parser.get_xml_element_tree_root(xsd_file_path, test_vocable_file_path) for vocable in xml_root: vocable_word_attribute_text = vocable.find(self.words_attribute_name).text # is this vocable one of the world list? if WordListHelper.is_in_list(WordListHelper, vocable_word_attribute_text, list_of_words, allow_whitespace_characters=True): print(vocable_word_attribute_text, 'is in word list') attribute_text = vocable.find(self.attribute_name).text # does this vocable have the added attribute value? regex = '\s*' + self.attribute_value + '\s*$' print('regex:', regex) print('attribute_text:', attribute_text) assert re.search(regex, attribute_text) is None, 'attribute value has already added to vocable ' + vocable.find(self.words_attribute_name).text # now add the attribute value xld_attribute_adder = XLDAttributeAdder(test_vocable_file_path, xsd_file_path, test_word_list_file_path) xld_attribute_adder.add_values_to_attribute_of_vocables(self.attribute_name, self.attribute_value, self.words_attribute_name) VocableFileWriter.write(VocableFileWriter, xsd_file_path, test_vocable_file_path, xld_attribute_adder.xml_root) # check the vocables again, to see if something has been added xml_root = xml_parser.get_xml_element_tree_root(xsd_file_path, test_vocable_file_path) for vocable in xml_root: vocable_word_attribute_text = vocable.find(self.words_attribute_name).text # is this vocable one of the world list? if WordListHelper.is_in_list(WordListHelper, vocable_word_attribute_text, list_of_words, allow_whitespace_characters=True): print(vocable_word_attribute_text, 'is in word list') attribute_text = vocable.find(self.attribute_name).text # does this vocable have the added attribute value? regex = '\s*' + self.attribute_value + '\s*$' print('regex:', regex) print('attribute_text:', attribute_text) assert re.search(regex, attribute_text) is not None, 'attribute value has not been added to vocable ' + vocable.find(self.words_attribute_name).text
def test_is_in_word_list (self): fail_message = 'word found or not found in word list although the opposite should be the case' allow_whitespace_characters = False assert WordListHelper.is_in_list(WordListHelper, 'a', ['a'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['a','b'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['b','a'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['b','a','c'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'a', ['b','c'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'a', ['b',' a','c'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'a', ['b','a ','c'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'a', ['b',' a ','c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['ab'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['b', 'ab'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['ab', 'c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['b', 'ab', 'c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['bd', 'ab', 'c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['b', 'ab', 'cd'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['bd', 'ab', 'cd'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['bde', 'ab', 'cd'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'ab', ['bde', 'cd'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'ab', ['bde', '', 'cd'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, '我', ['我'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, '你', ['你','b'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, '好', ['b','好'], allow_whitespace_characters), fail_message allow_whitespace_characters = True assert WordListHelper.is_in_list(WordListHelper, 'a', ['a'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'A', ['a'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'a', ['A'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['a','b'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['b','a'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['b','a','c'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'a', ['b','c'], allow_whitespace_characters), fail_message # with spaces assert WordListHelper.is_in_list(WordListHelper, 'a', ['b',' a','c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['b','a ','c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['b',' a ','c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['b',' a','c'], allow_whitespace_characters), fail_message # with tabs assert WordListHelper.is_in_list(WordListHelper, 'a', ['b','a ','c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['b',' a','c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['b',' a ','c'], allow_whitespace_characters), fail_message # with spaces and tabs assert WordListHelper.is_in_list(WordListHelper, 'a', ['b',' a ','c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'a', ['b',' a ','c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['ab'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['b', 'ab'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['ab', 'c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['b', 'ab', 'c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['bd', 'ab', 'c'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['b', 'ab', 'cd'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['bd', 'ab', 'cd'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'ab', ['bde', 'ab', 'cd'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'ab', ['bde', 'cd'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'ab', ['bde', '', 'cd'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, '我', ['我'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, '你', ['你','b'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, '好', ['b','好'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'Pīnyīn', ['Pīnyīn','好'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'Pīnyīn', ['b','好'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'níhǎoma', ['níhǎoma','好'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'níhǎoma', ['b','níhǎoma'], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, 'níhǎoma', ['test ', 'b','níhǎoma', '?!§', 'an1'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'níhǎoma', [' test', 'b','1níhǎoma', '?!§', 'an1'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'níhǎoma', [' test', 'b','níhǎoma3', '?!§', 'an1'], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, 'níhǎoma', [' test', 'b','1níhǎoma2', '?!§', 'an1'], allow_whitespace_characters), fail_message
def test_is_in_word_list(self): fail_message = "word found or not found in word list although the opposite should be the case" allow_whitespace_characters = False assert WordListHelper.is_in_list(WordListHelper, "a", ["a"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "a", ["a", "b"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "a", ["b", "a"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list( WordListHelper, "a", ["b", "a", "c"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list(WordListHelper, "a", ["b", "c"], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list( WordListHelper, "a", ["b", " a", "c"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list( WordListHelper, "a", ["b", "a ", "c"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list( WordListHelper, "a", ["b", " a ", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list(WordListHelper, "ab", ["ab"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "ab", ["b", "ab"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "ab", ["ab", "c"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list( WordListHelper, "ab", ["b", "ab", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "ab", ["bd", "ab", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "ab", ["b", "ab", "cd"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "ab", ["bd", "ab", "cd"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "ab", ["bde", "ab", "cd"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list( WordListHelper, "ab", ["bde", "cd"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list( WordListHelper, "ab", ["bde", "", "cd"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list(WordListHelper, "我", ["我"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "你", ["你", "b"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "好", ["b", "好"], allow_whitespace_characters), fail_message allow_whitespace_characters = True assert WordListHelper.is_in_list(WordListHelper, "a", ["a"], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, "A", ["a"], allow_whitespace_characters), fail_message assert not WordListHelper.is_in_list(WordListHelper, "a", ["A"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "a", ["a", "b"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "a", ["b", "a"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list( WordListHelper, "a", ["b", "a", "c"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list(WordListHelper, "a", ["b", "c"], allow_whitespace_characters), fail_message # with spaces assert WordListHelper.is_in_list( WordListHelper, "a", ["b", " a", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "a", ["b", "a ", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "a", ["b", " a ", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "a", ["b", " a", "c"], allow_whitespace_characters ), fail_message # with tabs assert WordListHelper.is_in_list( WordListHelper, "a", ["b", "a ", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "a", ["b", " a", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "a", ["b", " a ", "c"], allow_whitespace_characters ), fail_message # with spaces and tabs assert WordListHelper.is_in_list( WordListHelper, "a", ["b", " a ", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "a", ["b", " a ", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list(WordListHelper, "ab", ["ab"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "ab", ["b", "ab"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "ab", ["ab", "c"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list( WordListHelper, "ab", ["b", "ab", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "ab", ["bd", "ab", "c"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "ab", ["b", "ab", "cd"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "ab", ["bd", "ab", "cd"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "ab", ["bde", "ab", "cd"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list( WordListHelper, "ab", ["bde", "cd"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list( WordListHelper, "ab", ["bde", "", "cd"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list(WordListHelper, "我", ["我"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "你", ["你", "b"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list(WordListHelper, "好", ["b", "好"], allow_whitespace_characters), fail_message assert WordListHelper.is_in_list( WordListHelper, "Pīnyīn", ["Pīnyīn", "好"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list( WordListHelper, "Pīnyīn", ["b", "好"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "níhǎoma", ["níhǎoma", "好"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "níhǎoma", ["b", "níhǎoma"], allow_whitespace_characters ), fail_message assert WordListHelper.is_in_list( WordListHelper, "níhǎoma", ["test ", "b", "níhǎoma", "?!§", "an1"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list( WordListHelper, "níhǎoma", [" test", "b", "1níhǎoma", "?!§", "an1"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list( WordListHelper, "níhǎoma", [" test", "b", "níhǎoma3", "?!§", "an1"], allow_whitespace_characters ), fail_message assert not WordListHelper.is_in_list( WordListHelper, "níhǎoma", [" test", "b", "1níhǎoma2", "?!§", "an1"], allow_whitespace_characters ), fail_message