def test_add_empty_next_sentence(self): letter = XMLData("b", 10.0, 10.0, "Font", 23.0, True, False) next_sentence = "" p = PerthExtractor() expected_result = ["b"] actual_result = p.test_add_sentence(next_sentence, letter) self.assertTrue(expected_result == actual_result)
def test_letter_none(self): next_sentence = "aaa" letter = None p = PerthExtractor() expected_result = ["aaa"] actual_result = p.test_add_sentence(next_sentence, letter) self.assertTrue(expected_result == actual_result)
def test_return_empty_String(self): letter = self.xml_data_space next_sentence = "Hello" p = PerthExtractor() expected_result = "" actual_result = p.add_sentence(next_sentence, letter) self.assertTrue(expected_result == actual_result)
def test_dont_enter_while(self): xml_data = [] xml_data.append(XMLData("", 10.0, 15.0, "Font", 25.0, False, True)) xml_data.append(XMLData("", 10.0, 15.0, "Font", 25.0, False, True)) expected_result = [] p = PerthExtractor() actual_result = p.create_sentences(xml_data) self.assertTrue(all(elem in expected_result for elem in actual_result))
def test_remove_footer(self): xml_data = self.add_three_gap() xml_data.append(XMLData("", 10.0, 49.0, "Font", 23.0, False, True)) xml_data.insert(0, XMLData("", 10.0, 49.0, "Font", 23.0, False, True)) expected_result = [] p = PerthExtractor() actual_result = p.create_sentences(xml_data) self.assertTrue(all(elem in expected_result for elem in actual_result))
def test_skip_on_two_gap(self): xml_data = self.add_two_gap() xml_data.insert(0, XMLData("a", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("b", 16.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("b", 770.0, 100.0, "Font", 23.0, False, True)) expected_result = [] p = PerthExtractor() actual_result = p.create_sentences(xml_data) self.assertTrue(all(elem in expected_result for elem in actual_result))
def test_create_sentences_none(self): captured_output = io.StringIO() sys.stdout = captured_output xml_data = None p = PerthExtractor() expected_result = [] actual_result = p.create_sentences(xml_data) sys.stdout = sys.__stdout__ self.assertTrue(all(elem in expected_result for elem in actual_result))
def test_skip_all_gaps(self): xml_data = [] xml_data.append(XMLData(".", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("a", 270.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("b", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("c", 26.0, 10.0, "Font", 23.0, False, True)) xml_data.append(XMLData("d", 10.0, 10.0, "Font", 23.0, False, True)) expected_result = [] p = PerthExtractor() actual_result = p.create_sentences(xml_data) self.assertTrue(all(elem in expected_result for elem in actual_result))
def test_none_next_sentence(self): captured_output = io.StringIO() sys.stdout = captured_output letter = XMLData("b", 10.0, 10.0, "Font", 23.0, True, False) next_sentence = None p = PerthExtractor() expected_result = [] actual_result = p.test_add_sentence(next_sentence, letter) sys.stdout = sys.__stdout__ self.assertTrue(expected_result == actual_result)
def test_two_gap_add(self): #xml_data = self.add_two_gap() xml_data = [] xml_data.append(XMLData("A", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData(" ", 26.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData(" ", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("d", 26.0, 10.0, "Font", 23.0, False, True)) xml_data.append(XMLData("d", 10.0, 10.0, "Font", 23.0, False, True)) expected_result = [] p = PerthExtractor() actual_result = p.create_sentences(xml_data) self.assertTrue(all(elem in expected_result for elem in actual_result))
def test_two_words_no_removal(self): sentences = [] sentences.append("aaaa") sentences.append("bbbb") expected_result = sentences actual_result = PerthExtractor.call_remove(self, sentences) self.assertTrue(all(elem in expected_result for elem in actual_result))
def test_create_remove_footer(self): xml_data = [] xml_data.append(XMLData("a", 10.0, 10.0, "Font", 23.0, False, True)) xml_data.append(XMLData("b", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("c", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("d", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData(".", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData(" ", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("z", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("z", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("z", 10.0, 100.0, "Font", 23.0, False, True)) p = PerthExtractor() expected_result = ["bcd."] actual_result = p.create_sentences(xml_data) self.assertTrue(all(elem in expected_result for elem in actual_result))
def test_remove_short_sentence(self): sentences = [] sentences.append("ab") expected_result = [] actual_result = PerthExtractor.call_remove(self, sentences) self.assertTrue(all(elem in expected_result for elem in actual_result))
def test_immediate_exit(self): xml_data = [] xml_data.append(self.xml_data_space) expected_result = 13.0 actual_result = PerthExtractor.get_space_size(self, xml_data) self.assertTrue(expected_result == actual_result)
def test_xml_none(self): captured_output = io.StringIO() sys.stdout = captured_output xml_data = None expected_result = 0.0 actual_result = PerthExtractor.get_space_size(self, xml_data) sys.stdout = sys.__stdout__ self.assertTrue(expected_result == actual_result)
def test_false_on_space(self): xml_data = [] xml_data.append(XMLData(" ", 10.0, 10.0, "Font", 23.0, False, True)) xml_data.append(XMLData("b", 10.0, 100.0, "Font", 23.0, False, True)) xml_data.append(XMLData("c", 10.0, 100.0, "Font", 23.0, False, True)) expected_result = 0.0 actual_result = PerthExtractor.get_space_size(self, xml_data) self.assertTrue(expected_result == actual_result)
def test_xml_only_bold(self): xml_data = [] xml_data.append(XMLData("b", 270.0, 10.0, "Bold", 23.0, False, True)) xml_data.append(XMLData("c", 10.0, 10.0, "Bold", 23.0, False, True)) xml_data.append(XMLData("d", 10.0, 10.0, "Bold", 23.0, False, True)) expected_result = 13.0 actual_result = PerthExtractor.get_space_size(self, xml_data) self.assertTrue(expected_result == actual_result)
def test_false_on_y_gap(self): xml_data = [] xml_data.append(XMLData(" ", 10.0, 10.0, "Font", 24.0, False, True)) xml_data.append(XMLData("b", 10.0, 100.0, "Font", 24.0, False, True)) expected_result = 1 actual_result = PerthExtractor.check_for_repeated_phrases( self, xml_data, 0) self.assertTrue(expected_result == actual_result)
def test_finding_space_gap(self): xml_data = [] xml_data.append(self.xml_data_space) xml_data.append(self.xml_data_B) expected_result = 5.0 actual_result = PerthExtractor.get_space_size(self, xml_data) self.assertTrue(expected_result == actual_result)
def test_repeated_xml_none(self): captured_output = io.StringIO() sys.stdout = captured_output xml_data = None expected_result = 0.0 actual_result = PerthExtractor.check_for_repeated_phrases( self, xml_data, 0) sys.stdout = sys.__stdout__ self.assertTrue(expected_result == actual_result)
def test_reach_list_end_immediately(self): xml_data = [] xml_data.append(self.xml_data_space) expected_result = 1 actual_result = PerthExtractor.check_for_repeated_phrases( self, xml_data, 1) self.assertTrue(expected_result == actual_result)
def test_immediate_different_line(self): xml_data = [] xml_data.append(self.xml_data_y_1) xml_data.append(self.xml_data_space) expected_result = 1.0 actual_result = PerthExtractor.check_for_repeated_phrases( self, xml_data, 0) self.assertTrue(expected_result == actual_result)
def test_removed_character(self): xml_data = [] xml_data.append(self.xml_data_y_1) xml_data.append(self.xml_data_y_2) xml_data.append(self.xml_data_y_3) expected_result = 2.0 actual_result = PerthExtractor.check_for_repeated_phrases( self, xml_data, 0) self.assertTrue(expected_result == actual_result)
def test_execute_false_if(self): xml_data = [] xml_data.append(self.xml_data_space) xml_data.append(self.xml_data_space) xml_data.append(self.xml_data_B) expected_result = 5.0 actual_result = PerthExtractor.get_space_size(self, xml_data) self.assertTrue(expected_result == actual_result)
def test_double_loop(self): xml_data = [] xml_data.append(self.xml_data_y_1) xml_data.append(self.xml_data_y_1) xml_data.append(self.xml_data_y_1) xml_data.append(self.xml_data_space) expected_result = 3.0 actual_result = PerthExtractor.check_for_repeated_phrases( self, xml_data, 0) self.assertTrue(expected_result == actual_result)
def determine_factory(self, file_name): """Determine which CouncilExtractor will parse the XMLData. Using the name of the file passed in, determine which factory class, a CouncilExtractor, will parse the XMLData list. Args: file_name: The name of the file being parsed. Returns: PerthExtractor() or some other CouncilExtractor once they are implemented. """ try: file_name = file_name.lower() if "perth" in file_name: #print("Do the Perth one") return PerthExtractor() # Add a return Vincent class once we make a Vincent parser. elif "vincent" in file_name: return VincentExtractor() #print("do the vincent one") # Add a return Stirling class once we make the Stirling parser. elif "stirling" in file_name: print("Do the Stirling one") # If there isn't a recognised council in the file_name string then (for now), # raise an error, and later possibly later it will be changed to just parse # it for Perth. # If None is passed, throw a type error else: raise ValueError(file_name) except (TypeError, AttributeError) as e: message = "File_Name is not a String type: %s" % (e.args) raise TypeError(e.__str__() + "\n" + message)
def test_xml_empty(self): xml_data = [] expected_result = 13.0 actual_result = PerthExtractor.get_space_size(self, xml_data) self.assertTrue(expected_result == actual_result)
def test_only_spaces(self): sentences = [] sentences.append(" ") expected_result = sentences actual_result = PerthExtractor.call_remove(self, sentences) self.assertTrue(expected_result == actual_result)
def test_create_xml_empty(self): xml_data = [] p = PerthExtractor() expected_result = [] actual_result = p.create_sentences(xml_data) self.assertTrue(all(elem in expected_result for elem in actual_result))
def test_one_length(self): sentences = [] sentences.append("a") expected_result = [] actual_result = PerthExtractor.call_remove(self, sentences) self.assertTrue(actual_result == expected_result)