]> code.communitydata.science - mediawiki_dump_tools.git/blobdiff - test/Wikiq_Unit_Test.py
add namespace filter parameter
[mediawiki_dump_tools.git] / test / Wikiq_Unit_Test.py
index e43ee7defd31a2fcaa2eca23241d844354fb246e..91ac928c721f1fb788326069b52829b0823613f6 100644 (file)
@@ -51,6 +51,28 @@ class Test_Wikipedia(unittest.TestCase):
         baseline = pd.read_table(baseline_file)
         assert_frame_equal(test,baseline)
 
+    def test_WP_namespaces(self):
+        print(os.path.abspath('.'))
+        test_filename =  "namespaces_" + self.wikiq_out_name
+        test_file = os.path.join(self.test_output_dir, test_filename)
+        if os.path.exists(test_file):
+            os.remove(test_file)
+        
+        call = self.base_call.format(self.input_file, self.test_output_dir)
+        call = call + " -n 0 -n 1"
+        print(call)
+        proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True)
+        proc.wait()
+        copyfile(self.call_output, test_file)
+        baseline_file = os.path.join(os.path.abspath("."), self.baseline_output_dir, test_filename)
+
+        # as a test let's make sure that we get equal data frames
+        test = pd.read_table(test_file)
+        num_wrong_ns = sum(~ test.namespace.isin({0,1}))
+        self.assertEquals(num_wrong_ns, 0)
+        baseline = pd.read_table(baseline_file)
+        assert_frame_equal(test,baseline)
+
 
 class Test_Basic(unittest.TestCase):
 
@@ -108,6 +130,26 @@ class Test_Basic(unittest.TestCase):
         baseline = pd.read_table(baseline_file)
         assert_frame_equal(test,baseline)
 
+    def test_pwr_segment(self):
+        test_filename =  "persistence_segment_" + self.wikiq_out_name
+        test_file = os.path.join(self.test_output_dir, test_filename)
+        if os.path.exists(test_file):
+            os.remove(test_file)
+        
+        call = self.base_call.format(self.input_file, self.test_output_dir)
+        call = call + " --persistence segment"
+        proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True)
+        proc.wait()
+
+
+        copyfile(self.call_output, test_file)
+
+        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)
+
     def test_pwr_legacy(self):
         test_filename =  "persistence_legacy_" + self.wikiq_out_name
         test_file = os.path.join(self.test_output_dir, test_filename)
@@ -115,7 +157,7 @@ class Test_Basic(unittest.TestCase):
             os.remove(test_file)
         
         call = self.base_call.format(self.input_file, self.test_output_dir)
-        call = call + " --persistence-legacy"
+        call = call + " --persistence legacy"
         proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True)
         proc.wait()
 
@@ -131,8 +173,8 @@ class Test_Basic(unittest.TestCase):
     def test_pwr(self):
         test_filename =  "persistence_" + self.wikiq_out_name
         test_file = os.path.join(self.test_output_dir, test_filename)
-        if os.path.exists(test_file):
-            os.remove(test_file)
+        if os.path.exists(test_file): 
+           os.remove(test_file)
         
         call = self.base_call.format(self.input_file, self.test_output_dir)
         call = call + " --persistence"
@@ -169,7 +211,6 @@ class Test_Basic(unittest.TestCase):
 
 
 class Test_Malformed(unittest.TestCase):
-
     def setUp(self):
         if not os.path.exists("test_output"):
             os.mkdir("test_output")

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