+ 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)
+
+ test = test.reindex(columns=sorted(test.columns))
+ assert_frame_equal(test,baseline, check_like=True)
+
+
+class Test_Malformed(unittest.TestCase):
+ def setUp(self):
+ if not os.path.exists("test_output"):
+ os.mkdir("test_output")
+
+ 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.infile = "{0}.xml.7z".format(self.wiki)
+ self.base_call = "../wikiq {0} -o {1}"
+ self.input_dir = "dumps"
+ self.input_file = os.path.join(".", self.input_dir,self.infile)
+
+
+ def test_malformed_noargs(self):
+
+ call = self.base_call.format(self.input_file, self.test_output_dir)
+ proc = subprocess.Popen(call,stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True)
+ proc.wait()
+ outs, errs = proc.communicate()
+ 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(self.test_output_dir, "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(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(self.test_output_dir, "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(test_file)
+ baseline = pd.read_table(baseline_file)
+ assert_frame_equal(test,baseline, check_like=True)
+
+
+
+class Test_Stdout(unittest.TestCase):
+
+ def setUp(self):
+ self.wiki = 'itwiki'
+ self.wikiq_out_name = self.wiki + ".tsv"
+
+ self.infile = "{0}.xml.7z".format(self.wiki)
+ self.base_call = "../wikiq {0} --stdout"
+ self.input_dir = "dumps"
+ self.input_file = os.path.join(".", self.input_dir,self.infile)
+ self.baseline_output_dir = "baseline_output"
+
+ 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")
+
+ test_file = "noargs_" + self.wikiq_out_name