Remove resource leaks from tests
Close subprocesses within tests to fix resource leak warning. Signed-off-by: Will Beason <willbeason@gmail.com>
This commit is contained in:
13
wikiq
13
wikiq
@@ -97,6 +97,7 @@ class WikiqPage():
|
||||
# 3 A B True
|
||||
# 4 A A False
|
||||
# Post-loop A Always
|
||||
collapsed_revs = 0
|
||||
for i, rev in enumerate(self.mwpage):
|
||||
# never yield the first time
|
||||
if i == 0:
|
||||
@@ -491,7 +492,7 @@ class WikiqParser:
|
||||
# Construct dump file iterator
|
||||
dump = WikiqIterator(self.input_file, collapse_user=self.collapse_user)
|
||||
|
||||
# extract list of namspaces
|
||||
# extract list of namespaces
|
||||
self.namespaces = {ns.name: ns.id for ns in dump.mwiterator.site_info.namespaces}
|
||||
|
||||
page_count = 0
|
||||
@@ -703,7 +704,6 @@ class WikiqParser:
|
||||
line = rev_data.to_tsv_row()
|
||||
print(line, file=self.output_file)
|
||||
|
||||
|
||||
def open_input_file(input_filename):
|
||||
if re.match(r'.*\.7z$', input_filename):
|
||||
cmd = ["7za", "x", "-so", input_filename, "*.xml"]
|
||||
@@ -711,14 +711,13 @@ def open_input_file(input_filename):
|
||||
cmd = ["zcat", input_filename]
|
||||
elif re.match(r'.*\.bz2$', input_filename):
|
||||
cmd = ["bzcat", "-dk", input_filename]
|
||||
else:
|
||||
raise ValueError("Unrecognized file type: %s" % input_filename)
|
||||
|
||||
try:
|
||||
input_file = Popen(cmd, stdout=PIPE).stdout
|
||||
return Popen(cmd, stdout=PIPE).stdout
|
||||
except NameError:
|
||||
input_file = open(input_filename, 'r')
|
||||
|
||||
return input_file
|
||||
|
||||
return open(input_filename, 'r')
|
||||
|
||||
def get_output_filename(input_filename, parquet=False):
|
||||
output_filename = re.sub(r'\.(7z|gz|bz2)?$', '', input_filename)
|
||||
|
||||
Reference in New Issue
Block a user