X-Git-Url: https://code.communitydata.science/mediawiki_dump_tools.git/blobdiff_plain/4ccde845290a9ae350456107c1171638e81901e0..414cc5ff2d86c007b1a00c829c779627ea3b18d7:/test/Wikiq_Unit_Test.py diff --git a/test/Wikiq_Unit_Test.py b/test/Wikiq_Unit_Test.py index 159fd10..14d38f1 100644 --- a/test/Wikiq_Unit_Test.py +++ b/test/Wikiq_Unit_Test.py @@ -305,27 +305,33 @@ class Test_Regex(unittest.TestCase): self.baseline_output_dir = "baseline_output" # sample inputs for checking that bad inputs get terminated / test_regex_inputs - self.bad_input1 = "-RP '\\b\\d+\\b'" #label is missing - self.bad_input2 = "-RP 'NPO V' -RP THE -RPl testlabel" #number of reg and number of labels do not match - self.bad_input3 = "-CP '(Tamil|Li)' -RPl testlabel" #cp but rp label - self.bad_input4 = "-CPl testlabel" #regex is missing - self.bad_input5 = "-RP '\\b\\w{3}\\b' -RPl threeletters -CP '\\b\\w{3}\\b'" - - self.bad_inputs_list = [self.bad_input1,self.bad_input2,self.bad_input3,self.bad_input4,self.bad_input5] + self.bad_inputs_list = [ + #label is missing + "-RP '\\b\\d+\\b'", + #number of reg and number of labels do not match + "-RP 'NPO V' -RP THE -RPl testlabel", + #cp but rp label + "-CP '(Tamil|Li)' -RPl testlabel", + #regex is missing + "-CPl testlabel", + "-RP '\\b\\w{3}\\b' -RPl threeletters -CP '\\b\\w{3}\\b'" + ] # sample inputs for checking the outcomes of good inputs / test_basic_regex - self.good_input1 = "-RP '\\b\\d{3}\\b' -RPl threedigits" - self.good_input2 = "-RP 'TestCase' -RP 'page' -RPl testcases -RPl page_word" - self.good_input3 = "-CP 'Chevalier' -CPl chev_com -RP 'welcome to Wikipedia' -RPl wiki_welcome -CP 'Warning' -CPl warning" - self.good_input4 = "-CP 'WP:EVADE' -CPl wp_evade" + self.good_inputs_list = [ + "-RP '\\b\\d{3}\\b' -RPl threedigits", + "-RP 'TestCase' -RP 'page' -RPl testcases -RPl page_word", + "-CP 'Chevalier' -CPl chev_com -RP 'welcome to Wikipedia' -RPl wiki_welcome -CP 'Warning' -CPl warning", + "-CP 'WP:EVADE' -CPl wp_evade" + ] - self.good_inputs_list = [self.good_input1,self.good_input2,self.good_input3, self.good_input4] + + self.cap_inputs_list = [ + "-RP 'Li Chevalier' -RPl li_cheval -CP '(?P\\b[a-zA-Z]{3}\\b)|(?P\\b\\d+\\b)|(?P\\bcat\\b)' -CPl three", + "-CP '(?P\\bTestCaseA\\b)|(?P\\bTestCaseB\\b)|(?P\\bTestCaseC\\b)|(?P\\bTestCaseD\\b)' -CPl testcase -RP '(?Pnpov|NPOV)|(?Pneutral point of view)' -RPl npov" + ] - # and with capture group(s) / test_capturegroup_regex - self.cap_input1 = "-RP 'Li Chevalier' -RPl li_cheval -CP '(?P\\b[a-zA-Z]{3}\\b)|(?P\\b\\d+\\b)|(?P\\bcat\\b)' -CPl three" - self.cap_input2 = "-CP '(?P\\bTestCaseA\\b)|(?P\\bTestCaseB\\b)|(?P\\bTestCaseC\\b)|(?P\\bTestCaseD\\b)' -CPl testcase -RP '(?Pnpov|NPOV)|(?Pneutral point of view)' -RPl npov" - self.cap_inputs_list = [self.cap_input1,self.cap_input2] def test_regex_inputs(self): for input in self.bad_inputs_list: @@ -341,8 +347,7 @@ class Test_Regex(unittest.TestCase): self.assertNotEqual(proc.returncode,0) def test_basic_regex(self): - i = 1 - for input in self.good_inputs_list: + for i, input in enumerate(self.good_inputs_list): test_filename = "basic_{0}_{1}.tsv".format(self.wikiq_out_name[:-4], str(i)) #print(test_filename) @@ -356,22 +361,18 @@ class Test_Regex(unittest.TestCase): proc = subprocess.Popen(call,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True) proc.wait() - copyfile(self.call_output, test_file) - f = open(self.call_output, 'w') - f.close() - - # don't have a baseline file to compare a test to?? - # baseline_file = os.path.join(".", self.baseline_output_dir, test_filename) - i += 1 - #TODO - #a proper assert statement still needs to go here, but I checked out the generated files for now and it functions + test = pd.read_table(test_file) + + baseline_file = os.path.join(".", self.baseline_output_dir, test_filename) + baseline = pd.read_table(baseline_file) + assert_frame_equal(test, baseline) + print(i) def test_capturegroup_regex(self): - i = 1 - for input in self.cap_inputs_list: + for i, input in enumerate(self.cap_inputs_list): test_filename = "capturegroup_{0}_{1}.tsv".format(self.wikiq_out_name[:-4], str(i)) print(test_filename) test_file = os.path.join(self.test_output_dir, test_filename) @@ -386,15 +387,13 @@ class Test_Regex(unittest.TestCase): proc.wait() copyfile(self.call_output, test_file) - f = open(self.call_output, 'w') - f.close() - # don't have a baseline file to compare a test to?? - # baseline_file = os.path.join(".", self.baseline_output_dir, test_filename) - i += 1 + test = pd.read_table(test_file) + + baseline_file = os.path.join(".", self.baseline_output_dir, test_filename) + baseline = pd.read_table(baseline_file) + assert_frame_equal(test, baseline) - #TODO - #a proper assert statement still needs to go here, but I checked out the generated files for now and it functions if __name__ == '__main__': unittest.main()