X-Git-Url: https://code.communitydata.science/mediawiki_dump_tools.git/blobdiff_plain/e925ac9da10b20ab4ef949263887a1f9158e805f..d77b0a4965e59a3e5f84956b27dad58d98110c06:/test/Wikiq_Unit_Test.py diff --git a/test/Wikiq_Unit_Test.py b/test/Wikiq_Unit_Test.py index b32d6a9..ab0a532 100644 --- a/test/Wikiq_Unit_Test.py +++ b/test/Wikiq_Unit_Test.py @@ -32,15 +32,20 @@ class Test_Wikipedia(unittest.TestCase): self.baseline_output_dir = "baseline_output" def test_WP_url_encode(self): + test_filename = "url-encode_" + 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 + " --url-encode" proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True) proc.wait() - test_file = "url-encode_" + self.wikiq_out_name - copyfile(self.call_output, os.path.join(self.test_output_dir, test_file)) - baseline_file = os.path.join(".", self.baseline_output_dir, test_file) - test_lines = open(os.path.join(self.test_output_dir,test_file)) + copyfile(self.call_output, test_file) + baseline_file = os.path.join(".", self.baseline_output_dir, test_filename) + + test_lines = open(test_file) baseline_lines = open(baseline_file) for test, baseline in zip(test_lines, baseline_lines): self.assertEqual(test,baseline) @@ -68,35 +73,44 @@ class Test_Basic(unittest.TestCase): def test_noargs(self): + test_filename = "noargs_" + 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) proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True) proc.wait() - test_file = "noargs_" + self.wikiq_out_name - copyfile(self.call_output, os.path.join(self.test_output_dir, test_file)) - baseline_file = os.path.join(".", self.baseline_output_dir, test_file) + copyfile(self.call_output, test_file) + + baseline_file = os.path.join(".", self.baseline_output_dir, test_filename) - test_lines = open(os.path.join(self.test_output_dir,test_file)) + test_lines = open(test_file) baseline_lines = open(baseline_file) for test, baseline in zip(test_lines, baseline_lines): - self.assertEqual(test,baseline) + self.assertEqual(test, baseline) test_lines.close() baseline_lines.close() def test_collapse_user(self): + test_filename = "collapse-user_" + 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 + " --collapse-user" proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True) proc.wait() - test_file = "collapse-user_" + self.wikiq_out_name - copyfile(self.call_output, os.path.join(self.test_output_dir, test_file)) + copyfile(self.call_output, test_file) - baseline_file = os.path.join(".", self.baseline_output_dir, test_file) + baseline_file = os.path.join(".", self.baseline_output_dir, test_filename) - test_lines = open(os.path.join(self.test_output_dir,test_file)) + test_lines = open(test_file) baseline_lines = open(baseline_file) for test, baseline in zip(test_lines, baseline_lines): self.assertEqual(test,baseline) @@ -104,18 +118,23 @@ class Test_Basic(unittest.TestCase): test_lines.close() baseline_lines.close() - def test_pwr(self): + def test_pwr_legacy(self): + test_filename = "persistence_legacy_" + 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" + call = call + " --persistence-legacy" proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True) proc.wait() - test_file = "persistence_" + self.wikiq_out_name - copyfile(self.call_output, os.path.join(self.test_output_dir, test_file)) - baseline_file = os.path.join(".", self.baseline_output_dir, test_file) + copyfile(self.call_output, test_file) - test_lines = open(os.path.join(self.test_output_dir,test_file)) + baseline_file = os.path.join(".", self.baseline_output_dir, test_filename) + + test_lines = open(test_file) baseline_lines = open(baseline_file) for test, baseline in zip(test_lines, baseline_lines): self.assertEqual(test,baseline) @@ -124,15 +143,21 @@ class Test_Basic(unittest.TestCase): baseline_lines.close() def test_url_encode(self): + test_filename = "url-encode_" + 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 + " --url-encode" proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True) proc.wait() - test_file = "url-encode_" + self.wikiq_out_name - copyfile(self.call_output, os.path.join(self.test_output_dir, test_file)) - baseline_file = os.path.join(".", self.baseline_output_dir, test_file) - test_lines = open(os.path.join(self.test_output_dir,test_file)) + copyfile(self.call_output, test_file) + baseline_file = os.path.join(".", self.baseline_output_dir, test_filename) + + test_lines = open(test_file) baseline_lines = open(baseline_file) for test, baseline in zip(test_lines, baseline_lines): self.assertEqual(test,baseline) @@ -192,6 +217,20 @@ class Test_Stdout(unittest.TestCase): for test, baseline in zip(test_lines, baseline_lines): self.assertEqual(test,baseline) + def test_persistence(self): + + call = self.base_call.format(self.input_file) + " --persistence" + proc = subprocess.run(call,stdout=subprocess.PIPE,shell=True) + outs = proc.stdout.decode('utf-8') + + test_file = "persistence_" + self.wikiq_out_name + baseline_file = os.path.join(".", self.baseline_output_dir, test_file) + + test_lines = outs.splitlines(True) + baseline_lines = open(baseline_file) + for test, baseline in zip(test_lines, baseline_lines): + self.assertEqual(test,baseline) + # test_file = "noargs_" + self.wikiq_out_name # copyfile(self.call_output, os.path.join(self.test_output_dir, test_file))