]> code.communitydata.science - mediawiki_dump_tools.git/blobdiff - test/Wikiq_Unit_Test.py
fix bugs and unit tests
[mediawiki_dump_tools.git] / test / Wikiq_Unit_Test.py
index 14d38f12c2521d1f858ec9fc782e8ac5ad5ca23b..0a90c6cdec03c1b9492b4d9cc8251bad808fc1b2 100644 (file)
@@ -3,7 +3,7 @@ import os
 import subprocess
 from shutil import copyfile
 import pandas as pd
-from pandas.util.testing import assert_frame_equal
+from pandas.testing import assert_frame_equal
 from io import StringIO
 
 # with / without pwr DONE
@@ -49,7 +49,7 @@ class Test_Wikipedia(unittest.TestCase):
         # as a test let's make sure that we get equal data frames
         test = pd.read_table(test_file)
         baseline = pd.read_table(baseline_file)
-        assert_frame_equal(test,baseline)
+        assert_frame_equal(test,baseline, check_like=True)
 
     def test_WP_namespaces(self):
         print(os.path.abspath('.'))
@@ -71,7 +71,7 @@ class Test_Wikipedia(unittest.TestCase):
         num_wrong_ns = sum(~ test.namespace.isin({0,1}))
         self.assertEqual(num_wrong_ns, 0)
         baseline = pd.read_table(baseline_file)
-        assert_frame_equal(test,baseline)
+        assert_frame_equal(test,baseline, check_like=True)
 
     def test_WP_revert_radius(self):
         print(os.path.abspath('.'))
@@ -93,7 +93,7 @@ class Test_Wikipedia(unittest.TestCase):
         num_wrong_ns = sum(~ test.namespace.isin({0,1}))
         self.assertEqual(num_wrong_ns, 0)
         baseline = pd.read_table(baseline_file)
-        assert_frame_equal(test,baseline)
+        assert_frame_equal(test,baseline, check_like=True)
 
 
 
@@ -131,7 +131,7 @@ class Test_Basic(unittest.TestCase):
 
         test = pd.read_table(test_file)
         baseline = pd.read_table(baseline_file)
-        assert_frame_equal(test,baseline)
+        assert_frame_equal(test,baseline, check_like=True)
 
 
     def test_collapse_user(self):
@@ -151,7 +151,7 @@ class Test_Basic(unittest.TestCase):
         baseline_file = os.path.join(".", self.baseline_output_dir, test_filename)
         test = pd.read_table(test_file)
         baseline = pd.read_table(baseline_file)
-        assert_frame_equal(test,baseline)
+        assert_frame_equal(test,baseline, check_like=True)
 
     def test_pwr_segment(self):
         test_filename =  "persistence_segment_" + self.wikiq_out_name
@@ -171,7 +171,7 @@ class Test_Basic(unittest.TestCase):
 
         test = pd.read_table(test_file)
         baseline = pd.read_table(baseline_file)
-        assert_frame_equal(test,baseline)
+        assert_frame_equal(test,baseline, check_like=True)
 
     def test_pwr_legacy(self):
         test_filename =  "persistence_legacy_" + self.wikiq_out_name
@@ -191,7 +191,7 @@ class Test_Basic(unittest.TestCase):
 
         test = pd.read_table(test_file)
         baseline = pd.read_table(baseline_file)
-        assert_frame_equal(test,baseline)
+        assert_frame_equal(test,baseline, check_like=True)
 
     def test_pwr(self):
         test_filename =  "persistence_" + self.wikiq_out_name
@@ -211,7 +211,9 @@ class Test_Basic(unittest.TestCase):
 
         test = pd.read_table(test_file)
         baseline = pd.read_table(baseline_file)
-        assert_frame_equal(test,baseline)
+
+        test = test.reindex(columns=sorted(test.columns))
+        assert_frame_equal(test,baseline, check_like=True)
 
 
     def test_url_encode(self):
@@ -230,7 +232,9 @@ class Test_Basic(unittest.TestCase):
         baseline_file = os.path.join(".", self.baseline_output_dir, test_filename)
         test = pd.read_table(test_file)
         baseline = pd.read_table(baseline_file)
-        assert_frame_equal(test,baseline)
+
+        test = test.reindex(columns=sorted(test.columns))
+        assert_frame_equal(test,baseline, check_like=True)
 
 
 class Test_Malformed(unittest.TestCase):
@@ -241,7 +245,7 @@ class Test_Malformed(unittest.TestCase):
         self.wiki = 'twinpeaks'
         self.wikiq_out_name =  self.wiki + ".tsv"
         self.test_output_dir = os.path.join(".", "test_output")
-        self.call_output = os.path.join(self.test_output_dir, self.wikiq_out_name)
+        self.call_output = os.path.join(self.test_output_dir, self.wikiq_out_name) 
 
         self.infile = "{0}.xml.7z".format(self.wiki)
         self.base_call = "../wikiq {0} -o {1}"
@@ -273,6 +277,7 @@ class Test_Stdout(unittest.TestCase):
     def test_noargs(self):
 
         call = self.base_call.format(self.input_file)
+        print(call)
         proc = subprocess.run(call,stdout=subprocess.PIPE,shell=True)
         outs = proc.stdout.decode("utf8")
 
@@ -281,7 +286,7 @@ class Test_Stdout(unittest.TestCase):
         print(baseline_file)
         test = pd.read_table(StringIO(outs))
         baseline = pd.read_table(baseline_file)
-        assert_frame_equal(test,baseline)
+        assert_frame_equal(test,baseline, check_like=True)
 
 class Test_Regex(unittest.TestCase):
 
@@ -367,7 +372,7 @@ class Test_Regex(unittest.TestCase):
             
             baseline_file = os.path.join(".", self.baseline_output_dir, test_filename)
             baseline = pd.read_table(baseline_file)
-            assert_frame_equal(test, baseline)
+            assert_frame_equal(test, baseline, check_like=True)
             print(i)
 
 
@@ -392,7 +397,7 @@ class Test_Regex(unittest.TestCase):
             
             baseline_file = os.path.join(".", self.baseline_output_dir, test_filename)
             baseline = pd.read_table(baseline_file)
-            assert_frame_equal(test, baseline)
+            assert_frame_equal(test, baseline, check_like=True)
 
 
 if __name__ == '__main__':

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