diff --git a/hepcrawl/pipelines.py b/hepcrawl/pipelines.py index c464c7a0..9e3d84e8 100644 --- a/hepcrawl/pipelines.py +++ b/hepcrawl/pipelines.py @@ -24,7 +24,7 @@ from inspire_schemas.utils import validate -from hepcrawl.crawler2hep import item_to_hep +from hepcrawl.tohep import item_to_hep from hepcrawl.settings import FILES_STORE from hepcrawl.utils import RecordFile diff --git a/hepcrawl/testlib/fixtures.py b/hepcrawl/testlib/fixtures.py index c9d53339..a5d897b2 100644 --- a/hepcrawl/testlib/fixtures.py +++ b/hepcrawl/testlib/fixtures.py @@ -17,7 +17,12 @@ from scrapy.selector import Selector -def fake_response_from_file(file_name, test_suite='unit', url='http://www.example.com', response_type=TextResponse): +def fake_response_from_file( + file_name, + test_suite='unit', + url='http://www.example.com', + response_type=TextResponse, +): """Create a Scrapy fake HTTP response from a HTML file Args: @@ -26,11 +31,12 @@ def fake_response_from_file(file_name, test_suite='unit', url='http://www.exampl test_suite(str): The test suite that the response file comes from, e.g. ``unit``, ``functional``. url(str): The URL of the response. - response_type: The type of the scrapy Response to be returned, + response_type(class): The type of the scrapy Response to be returned, depending on the Request (Response, TextResponse, etc). Returns: - ``response_type``: A scrapy HTTP response which can be used for unit testing. + ``response_type``: A scrapy HTTP response which can be used for unit + testing. """ request = Request(url=url) @@ -55,15 +61,18 @@ def fake_response_from_file(file_name, test_suite='unit', url='http://www.exampl return response -def fake_response_from_string(text, url='http://www.example.com', response_type=TextResponse): - """Fake Scrapy response from a string.""" +def fake_response_from_string( + text, + url='http://www.example.com', + response_type=TextResponse, +): request = Request(url=url) response = response_type( url=url, request=request, body=text, - **{'encoding': 'utf-8'} - ) + encoding='utf-8', + ) return response @@ -83,7 +92,8 @@ def get_node(spider, tag, response=None, text=None, rtype="xml"): def get_test_suite_path(*path_chunks, **kwargs): """ Args: - *path_chunks: Optional extra path element (strings) to suffix the responses directory with. + *path_chunks: Optional extra path element (strings) to suffix the + responses directory with. **kwargs: The test type folder name, default is the ``unit`` test suite, e.g. ``test_suite='unit'``, ``test_suite='functional'``. diff --git a/hepcrawl/crawler2hep.py b/hepcrawl/tohep.py similarity index 100% rename from hepcrawl/crawler2hep.py rename to hepcrawl/tohep.py diff --git a/hepcrawl/utils.py b/hepcrawl/utils.py index 9d66b565..7febb270 100644 --- a/hepcrawl/utils.py +++ b/hepcrawl/utils.py @@ -373,7 +373,7 @@ class RecordFile(object): name(str): Optional, name of the file, if not passed, will use the name in the ``path``. - Rises: + Raises: PathDoesNotExist: """ def __init__(self, path, name=None): diff --git a/tests/unit/responses/crawler2hep/in_generic_crawler_record.yaml b/tests/unit/responses/tohep/in_generic_hepcrawl_record.yaml similarity index 100% rename from tests/unit/responses/crawler2hep/in_generic_crawler_record.yaml rename to tests/unit/responses/tohep/in_generic_hepcrawl_record.yaml diff --git a/tests/unit/responses/crawler2hep/in_no_document_type.yaml b/tests/unit/responses/tohep/in_no_document_type.yaml similarity index 100% rename from tests/unit/responses/crawler2hep/in_no_document_type.yaml rename to tests/unit/responses/tohep/in_no_document_type.yaml diff --git a/tests/unit/responses/crawler2hep/out_generic_crawler_record.yaml b/tests/unit/responses/tohep/out_generic_hepcrawl_record.yaml similarity index 100% rename from tests/unit/responses/crawler2hep/out_generic_crawler_record.yaml rename to tests/unit/responses/tohep/out_generic_hepcrawl_record.yaml diff --git a/tests/unit/responses/crawler2hep/out_no_document_type.yaml b/tests/unit/responses/tohep/out_no_document_type.yaml similarity index 100% rename from tests/unit/responses/crawler2hep/out_no_document_type.yaml rename to tests/unit/responses/tohep/out_no_document_type.yaml diff --git a/tests/unit/test_crawler2hep.py b/tests/unit/test_tohep.py similarity index 69% rename from tests/unit/test_crawler2hep.py rename to tests/unit/test_tohep.py index 5d0ea837..8ff479a8 100644 --- a/tests/unit/test_crawler2hep.py +++ b/tests/unit/test_tohep.py @@ -12,14 +12,14 @@ import pytest import yaml -from hepcrawl.crawler2hep import hepcrawl_to_hep +from hepcrawl.tohep import hepcrawl_to_hep from hepcrawl.testlib.fixtures import get_test_suite_path def load_file(file_name): path = get_test_suite_path( 'responses', - 'crawler2hep', + 'tohep', file_name, ) with open(path) as input_data: @@ -29,13 +29,13 @@ def load_file(file_name): @pytest.fixture('module') -def expected_generic_crawler_record(): - return load_file('out_generic_crawler_record.yaml') +def expected_generic_hepcrawl_record(): + return load_file('out_generic_hepcrawl_record.yaml') @pytest.fixture('module') -def input_generic_crawler_record(): - return load_file('in_generic_crawler_record.yaml') +def input_generic_hepcrawl_record(): + return load_file('in_generic_hepcrawl_record.yaml') @pytest.fixture('module') @@ -48,12 +48,12 @@ def input_no_document_type_record(): return load_file('in_no_document_type.yaml') -def test_generic_crawler_record( - input_generic_crawler_record, - expected_generic_crawler_record +def test_generic_hepcrawl_record( + input_generic_hepcrawl_record, + expected_generic_hepcrawl_record ): - produced_record = hepcrawl_to_hep(input_generic_crawler_record) - assert produced_record == expected_generic_crawler_record + produced_record = hepcrawl_to_hep(input_generic_hepcrawl_record) + assert produced_record == expected_generic_hepcrawl_record def test_no_document_type(