Skip to content

Commit

Permalink
testlib: refactored clean_dir default arguments
Browse files Browse the repository at this point in the history
* Adds: new default argument to `clean_dir` method is the generated DB folder from `scrapy-crawl-once` plugin.

Addresses inspirehep#161

Signed-off-by: Spiros Delviniotis <[email protected]>
  • Loading branch information
spirosdelviniotis committed Aug 18, 2017
1 parent 063663b commit f50d983
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
7 changes: 6 additions & 1 deletion hepcrawl/testlib/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,10 @@ def expected_json_results_from_file(*path_chunks, **kwargs):
return expected_data


def clean_dir(path='/tmp/WSP/'):
def clean_dir(path=os.path.join(os.getcwd(), '.scrapy')):
"""
Args:
path(str): path of directory to be deleted. Default path is the produced DB per spider that
stores the requested urls.
"""
shutil.rmtree(path, ignore_errors=True)
3 changes: 1 addition & 2 deletions tests/functional/arxiv/test_arxiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from __future__ import absolute_import, division, print_function

import os
from time import sleep
import pytest

Expand Down Expand Up @@ -53,7 +52,7 @@ def set_up_local_environment():
}
}

clean_dir(path=os.path.join(os.getcwd(), '.scrapy'))
clean_dir()


@pytest.mark.parametrize(
Expand Down
17 changes: 2 additions & 15 deletions tests/functional/wsp/test_wsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from __future__ import absolute_import, division, print_function

import pytest
import os

from time import sleep

Expand Down Expand Up @@ -44,7 +43,7 @@ def set_up_ftp_environment():
)

# The test must wait until the docker environment is up (takes about 10 seconds).
sleep(7)
sleep(10)

yield {
'CRAWLER_HOST_URL': 'http://scrapyd:6800',
Expand All @@ -55,7 +54,7 @@ def set_up_ftp_environment():
}
}

clean_dir(path=os.path.join(os.getcwd(), '.scrapy'))
clean_dir()


@pytest.fixture(scope="function")
Expand All @@ -76,19 +75,7 @@ def set_up_local_environment():
}
}

remove_generated_files(package_location)


def remove_generated_files(package_location):
clean_dir()
clean_dir(path=os.path.join(os.getcwd(), '.scrapy'))

_, dirs, files = next(os.walk(package_location))
for dir_name in dirs:
clean_dir(os.path.join(package_location, dir_name))
for file_name in files:
if not file_name.endswith('.zip'):
os.unlink(os.path.join(package_location, file_name))


@pytest.mark.parametrize(
Expand Down

0 comments on commit f50d983

Please sign in to comment.