]> code.communitydata.science - mediawiki_dump_tools.git/blobdiff - test/Wikiq_Unit_Test.py
write regex captures to parquet arrays.
[mediawiki_dump_tools.git] / test / Wikiq_Unit_Test.py
index 0a90c6cdec03c1b9492b4d9cc8251bad808fc1b2..129abfe7dbd397c6c847e77f5be8856d1f5e1ed3 100644 (file)
@@ -262,6 +262,82 @@ class Test_Malformed(unittest.TestCase):
         errlines = str(errs).split("\\n")
         self.assertEqual(errlines[-2],'xml.etree.ElementTree.ParseError: no element found: line 1369, column 0')
 
         errlines = str(errs).split("\\n")
         self.assertEqual(errlines[-2],'xml.etree.ElementTree.ParseError: no element found: line 1369, column 0')
 
+
+class Test_Redirect_Ikwiki(unittest.TestCase):
+    def setUp(self):
+        self.wiki = 'ikwiki-20180301-pages-meta-history'
+        wiki_siteinfo = "ikwiki-20191101-siteinfo-namespaces.json.gz"
+        self.input_dir = "dumps"
+        self.wiki_siteinfo = os.path.join(".", self.input_dir, wiki_siteinfo)
+        self.wikiq_out_name =  self.wiki + ".tsv"
+        self.infile = "{0}.xml.bz2".format(self.wiki)    
+
+        self.base_call = "../wikiq {0} --siteinfo {1} -o {2}"
+        self.input_dir = "dumps"
+        self.input_file = os.path.join(".", self.input_dir, self.infile)
+        self.baseline_output_dir = "baseline_output"
+
+        self.test_output_dir = os.path.join(".", "test_output")
+        self.call_output = os.path.join(self.test_output_dir, self.wikiq_out_name)
+
+        self.infile = "{0}.xml.bz2".format(self.wiki)    
+
+    def test_redirect(self):
+
+        call = self.base_call.format(self.input_file, self.wiki_siteinfo, self.test_output_dir)
+        print(call)
+        proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True)
+        proc.wait()
+
+        test_file = os.path.join("redirect_" + self.wikiq_out_name)
+        copyfile(self.call_output, test_file)
+        baseline_file = os.path.join(".", self.baseline_output_dir, test_file)
+
+        # as a test let's make sure that we get equal data frames
+        test = pd.read_table(os.path.join(self.test_output_dir, test_file))
+
+        baseline = pd.read_table(baseline_file)
+        assert_frame_equal(test,baseline, check_like=True)
+
+
+
+class Test_Redirect_Wikia(unittest.TestCase):
+    def setUp(self):
+        self.wiki = 'pokemonfandomcom_fr-20200215-history'
+        wiki_siteinfo = "pokemonfandomcom_fr-20200215-history.xml.7z"
+        self.input_dir = "dumps"
+        self.wiki_siteinfo = os.path.join(".", self.input_dir, wiki_siteinfo)
+        self.wikiq_out_name =  self.wiki + ".tsv"
+        self.infile = "{0}.xml.7z".format(self.wiki)    
+
+        self.base_call = "../wikiq {0} --siteinfo {1} -o {2}"
+        self.input_dir = "dumps"
+        self.input_file = os.path.join(".", self.input_dir, self.infile)
+        self.baseline_output_dir = "baseline_output"
+
+        self.test_output_dir = os.path.join(".", "test_output")
+        self.call_output = os.path.join(self.test_output_dir, self.wikiq_out_name)
+
+        self.infile = "{0}.xml.7z".format(self.wiki)    
+
+    def test_redirect(self):
+
+        call = self.base_call.format(self.input_file, self.wiki_siteinfo, self.test_output_dir)
+        print(call)
+        proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True)
+        proc.wait()
+
+        test_file = os.path.join("redirect_" + self.wikiq_out_name)
+        copyfile(self.call_output, test_file)
+        baseline_file = os.path.join(".", self.baseline_output_dir, test_file)
+
+        # as a test let's make sure that we get equal data frames
+        test = pd.read_table(os.path.join(self.test_output_dir, test_file))
+        baseline = pd.read_table(baseline_file)
+        assert_frame_equal(test,baseline, check_like=True)
+
+
+    
 class Test_Stdout(unittest.TestCase):
 
     def setUp(self):
 class Test_Stdout(unittest.TestCase):
 
     def setUp(self):
@@ -284,9 +360,11 @@ class Test_Stdout(unittest.TestCase):
         test_file = "noargs_" + self.wikiq_out_name
         baseline_file = os.path.join(".", self.baseline_output_dir, test_file)
         print(baseline_file)
         test_file = "noargs_" + self.wikiq_out_name
         baseline_file = os.path.join(".", self.baseline_output_dir, test_file)
         print(baseline_file)
-        test = pd.read_table(StringIO(outs))
+        s = StringIO(outs)
+        test = pd.read_table(s)
         baseline = pd.read_table(baseline_file)
         assert_frame_equal(test,baseline, check_like=True)
         baseline = pd.read_table(baseline_file)
         assert_frame_equal(test,baseline, check_like=True)
+        
 
 class Test_Regex(unittest.TestCase):
 
 
 class Test_Regex(unittest.TestCase):
 
@@ -339,9 +417,9 @@ class Test_Regex(unittest.TestCase):
 
 
     def test_regex_inputs(self):
 
 
     def test_regex_inputs(self):
-        for input in self.bad_inputs_list:
+        for inpt in self.bad_inputs_list:
             call = self.base_call.format(self.input_file)
             call = self.base_call.format(self.input_file)
-            call = call + " --stdout " + input
+            call = call + " --stdout " + inpt
             print(call)
             proc = subprocess.Popen(call,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
             stdout,stderr = proc.communicate()
             print(call)
             proc = subprocess.Popen(call,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
             stdout,stderr = proc.communicate()
@@ -352,7 +430,7 @@ class Test_Regex(unittest.TestCase):
             self.assertNotEqual(proc.returncode,0)
 
     def test_basic_regex(self):
             self.assertNotEqual(proc.returncode,0)
 
     def test_basic_regex(self):
-        for i, input in enumerate(self.good_inputs_list):
+        for i, inpt in enumerate(self.good_inputs_list):
 
             test_filename = "basic_{0}_{1}.tsv".format(self.wikiq_out_name[:-4], str(i))
             #print(test_filename)
 
             test_filename = "basic_{0}_{1}.tsv".format(self.wikiq_out_name[:-4], str(i))
             #print(test_filename)
@@ -361,7 +439,7 @@ class Test_Regex(unittest.TestCase):
                 os.remove(test_file)
 
             call = self.base_call_outs.format(self.input_file, self.test_output_dir)
                 os.remove(test_file)
 
             call = self.base_call_outs.format(self.input_file, self.test_output_dir)
-            call = call + " " + input
+            call = call + " " + inpt
             print(call)
 
             proc = subprocess.Popen(call,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
             print(call)
 
             proc = subprocess.Popen(call,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
@@ -377,7 +455,7 @@ class Test_Regex(unittest.TestCase):
 
 
     def test_capturegroup_regex(self):
 
 
     def test_capturegroup_regex(self):
-        for i, input in enumerate(self.cap_inputs_list):
+        for i, inpt 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)
             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)
@@ -385,7 +463,7 @@ class Test_Regex(unittest.TestCase):
                 os.remove(test_file)
 
             call = self.base_call_outs.format(self.input_file, self.test_output_dir)
                 os.remove(test_file)
 
             call = self.base_call_outs.format(self.input_file, self.test_output_dir)
-            call = call + " " + input
+            call = call + " " + inpt
             print(call)
 
             proc = subprocess.Popen(call,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
             print(call)
 
             proc = subprocess.Popen(call,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)

Community Data Science Collective || Want to submit a patch?