4 from shutil import copyfile
6 # with / without pwr DONE
7 # with / without url encode DONE
8 # with / without collapse user DONE
9 # with output to sdtout
10 # note that the persistence radius is 7 by default
11 # reading various file formats including
13 # wikia and wikipedia data
16 class Test_Basic(unittest.TestCase):
19 if not os.path.exists("test_output"):
20 os.mkdir("test_output")
22 self.wiki = 'sailormoon'
23 self.wikiq_out_name = self.wiki + ".tsv"
24 self.test_output_dir = os.path.join(".", "test_output")
25 self.call_output = os.path.join(self.test_output_dir, self.wikiq_out_name)
27 self.infile = "{0}.xml.7z".format(self.wiki)
28 self.base_call = "../wikiq {0} -o {1}"
29 self.input_dir = "dumps"
30 self.input_file = os.path.join(".", self.input_dir,self.infile)
31 self.baseline_output_dir = "baseline_output"
33 def test_noargs(self):
35 call = self.base_call.format(self.input_file, self.test_output_dir)
38 test_file = "noargs_" + self.wikiq_out_name
39 copyfile(self.call_output, os.path.join(self.test_output_dir, test_file))
41 baseline_file = os.path.join(".", self.baseline_output_dir, test_file)
43 test_lines = open(os.path.join(self.test_output_dir,test_file))
44 baseline_lines = open(baseline_file)
45 for test, baseline in zip(test_lines, baseline_lines):
46 self.assertEqual(test,baseline)
49 baseline_lines.close()
51 def test_collapse_user(self):
52 call = self.base_call.format(self.input_file, self.test_output_dir)
54 call = call + " --collapse-user"
58 test_file = "collapse-user_" + self.wikiq_out_name
59 copyfile(self.call_output, os.path.join(self.test_output_dir, test_file))
61 baseline_file = os.path.join(".", self.baseline_output_dir, test_file)
63 test_lines = open(os.path.join(self.test_output_dir,test_file))
64 baseline_lines = open(baseline_file)
65 for test, baseline in zip(test_lines, baseline_lines):
66 self.assertEqual(test,baseline)
69 baseline_lines.close()
72 call = self.base_call.format(self.input_file, self.test_output_dir)
73 call = call + " --persistence"
76 test_file = "persistence_" + self.wikiq_out_name
77 copyfile(self.call_output, os.path.join(self.test_output_dir, test_file))
79 baseline_file = os.path.join(".", self.baseline_output_dir, test_file)
81 test_lines = open(os.path.join(self.test_output_dir,test_file))
82 baseline_lines = open(baseline_file)
83 for test, baseline in zip(test_lines, baseline_lines):
84 self.assertEqual(test,baseline)
87 baseline_lines.close()
89 def test_url_encode(self):
90 call = self.base_call.format(self.input_file, self.test_output_dir)
91 call = call + " --url-encode"
93 test_file = "url-encode_" + self.wikiq_out_name
94 copyfile(self.call_output, os.path.join(self.test_output_dir, test_file))
95 baseline_file = os.path.join(".", self.baseline_output_dir, test_file)
97 test_lines = open(os.path.join(self.test_output_dir,test_file))
98 baseline_lines = open(baseline_file)
99 for test, baseline in zip(test_lines, baseline_lines):
100 self.assertEqual(test,baseline)
103 baseline_lines.close()
107 if __name__ == '__main__':