add tests for wikipedia, malformed xml, bzip2, correct bz2 bug in wikiq.
This commit is contained in:
parent
d2746879d0
commit
e925ac9da1
@ -1,17 +1,53 @@
|
|||||||
import unittest
|
import unittest
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import subprocess
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
import pdb
|
||||||
|
|
||||||
# with / without pwr DONE
|
# with / without pwr DONE
|
||||||
# with / without url encode DONE
|
# with / without url encode DONE
|
||||||
# with / without collapse user DONE
|
# with / without collapse user DONE
|
||||||
# with output to sdtout
|
# with output to sdtout DONE
|
||||||
# note that the persistence radius is 7 by default
|
# note that the persistence radius is 7 by default
|
||||||
# reading various file formats including
|
# reading various file formats including
|
||||||
# 7z, gz, bz2, xml
|
# 7z, gz, bz2, xml DONE
|
||||||
# wikia and wikipedia data
|
# wikia and wikipedia data DONE
|
||||||
# malformed xmls
|
# malformed xmls DONE
|
||||||
|
|
||||||
|
class Test_Wikipedia(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
if not os.path.exists("test_output"):
|
||||||
|
os.mkdir("test_output")
|
||||||
|
|
||||||
|
self.wiki = 'ikwiki-20180301-pages-meta-history'
|
||||||
|
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.bz2".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)
|
||||||
|
self.baseline_output_dir = "baseline_output"
|
||||||
|
|
||||||
|
def test_WP_url_encode(self):
|
||||||
|
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))
|
||||||
|
baseline_lines = open(baseline_file)
|
||||||
|
for test, baseline in zip(test_lines, baseline_lines):
|
||||||
|
self.assertEqual(test,baseline)
|
||||||
|
|
||||||
|
test_lines.close()
|
||||||
|
baseline_lines.close()
|
||||||
|
|
||||||
|
|
||||||
class Test_Basic(unittest.TestCase):
|
class Test_Basic(unittest.TestCase):
|
||||||
|
|
||||||
@ -33,8 +69,8 @@ class Test_Basic(unittest.TestCase):
|
|||||||
def test_noargs(self):
|
def test_noargs(self):
|
||||||
|
|
||||||
call = self.base_call.format(self.input_file, self.test_output_dir)
|
call = self.base_call.format(self.input_file, self.test_output_dir)
|
||||||
os.system(call)
|
proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True)
|
||||||
|
proc.wait()
|
||||||
test_file = "noargs_" + self.wikiq_out_name
|
test_file = "noargs_" + self.wikiq_out_name
|
||||||
copyfile(self.call_output, os.path.join(self.test_output_dir, test_file))
|
copyfile(self.call_output, os.path.join(self.test_output_dir, test_file))
|
||||||
|
|
||||||
@ -50,10 +86,10 @@ class Test_Basic(unittest.TestCase):
|
|||||||
|
|
||||||
def test_collapse_user(self):
|
def test_collapse_user(self):
|
||||||
call = self.base_call.format(self.input_file, self.test_output_dir)
|
call = self.base_call.format(self.input_file, self.test_output_dir)
|
||||||
os.system(call)
|
|
||||||
call = call + " --collapse-user"
|
call = call + " --collapse-user"
|
||||||
|
|
||||||
os.system(call)
|
proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True)
|
||||||
|
proc.wait()
|
||||||
|
|
||||||
test_file = "collapse-user_" + self.wikiq_out_name
|
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, os.path.join(self.test_output_dir, test_file))
|
||||||
@ -71,7 +107,8 @@ class Test_Basic(unittest.TestCase):
|
|||||||
def test_pwr(self):
|
def test_pwr(self):
|
||||||
call = self.base_call.format(self.input_file, self.test_output_dir)
|
call = self.base_call.format(self.input_file, self.test_output_dir)
|
||||||
call = call + " --persistence"
|
call = call + " --persistence"
|
||||||
os.system(call)
|
proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True)
|
||||||
|
proc.wait()
|
||||||
|
|
||||||
test_file = "persistence_" + self.wikiq_out_name
|
test_file = "persistence_" + self.wikiq_out_name
|
||||||
copyfile(self.call_output, os.path.join(self.test_output_dir, test_file))
|
copyfile(self.call_output, os.path.join(self.test_output_dir, test_file))
|
||||||
@ -89,7 +126,8 @@ class Test_Basic(unittest.TestCase):
|
|||||||
def test_url_encode(self):
|
def test_url_encode(self):
|
||||||
call = self.base_call.format(self.input_file, self.test_output_dir)
|
call = self.base_call.format(self.input_file, self.test_output_dir)
|
||||||
call = call + " --url-encode"
|
call = call + " --url-encode"
|
||||||
os.system(call)
|
proc = subprocess.Popen(call,stdout=subprocess.PIPE,shell=True)
|
||||||
|
proc.wait()
|
||||||
test_file = "url-encode_" + self.wikiq_out_name
|
test_file = "url-encode_" + self.wikiq_out_name
|
||||||
copyfile(self.call_output, os.path.join(self.test_output_dir, test_file))
|
copyfile(self.call_output, os.path.join(self.test_output_dir, test_file))
|
||||||
baseline_file = os.path.join(".", self.baseline_output_dir, test_file)
|
baseline_file = os.path.join(".", self.baseline_output_dir, test_file)
|
||||||
@ -102,6 +140,69 @@ class Test_Basic(unittest.TestCase):
|
|||||||
test_lines.close()
|
test_lines.close()
|
||||||
baseline_lines.close()
|
baseline_lines.close()
|
||||||
|
|
||||||
|
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_Stdout(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.wiki = 'sailormoon'
|
||||||
|
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)
|
||||||
|
proc = subprocess.run(call,stdout=subprocess.PIPE,shell=True)
|
||||||
|
outs = proc.stdout.decode('utf-8')
|
||||||
|
|
||||||
|
test_file = "noargs_" + 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))
|
||||||
|
|
||||||
|
# baseline_file = os.path.join(".", self.baseline_output_dir, test_file)
|
||||||
|
|
||||||
|
# test_lines = open(os.path.join(self.test_output_dir,test_file))
|
||||||
|
# baseline_lines = open(baseline_file)
|
||||||
|
# for test, baseline in zip(test_lines, baseline_lines):
|
||||||
|
# self.assertEqual(test,baseline)
|
||||||
|
# test_lines.close()
|
||||||
|
# baseline_lines.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
27780
test/baseline_output/url-encode_ikwiki-20180301-pages-meta-history.tsv
Normal file
27780
test/baseline_output/url-encode_ikwiki-20180301-pages-meta-history.tsv
Normal file
File diff suppressed because it is too large
Load Diff
BIN
test/dumps/ikwiki-20180301-pages-meta-history.xml.bz2
Normal file
BIN
test/dumps/ikwiki-20180301-pages-meta-history.xml.bz2
Normal file
Binary file not shown.
BIN
test/dumps/twinpeaks.xml.7z
Normal file
BIN
test/dumps/twinpeaks.xml.7z
Normal file
Binary file not shown.
2
wikiq
2
wikiq
@ -277,7 +277,7 @@ def open_input_file(input_filename):
|
|||||||
elif re.match(r'.*\.gz$', input_filename):
|
elif re.match(r'.*\.gz$', input_filename):
|
||||||
cmd = ["zcat", input_filename]
|
cmd = ["zcat", input_filename]
|
||||||
elif re.match(r'.*\.bz2$', input_filename):
|
elif re.match(r'.*\.bz2$', input_filename):
|
||||||
cmd = ["zcat", input_filename]
|
cmd = ["bzcat", "-dk", input_filename]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
input_file = Popen(cmd, stdout=PIPE).stdout
|
input_file = Popen(cmd, stdout=PIPE).stdout
|
||||||
|
Loading…
Reference in New Issue
Block a user