From 4bb25cec68f1b2613a906e416d4ee3abf9050f6d Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 2 Nov 2021 16:47:10 -0700 Subject: hacks to work around new pylint false positives --- python/fatcat_tools/workers/elasticsearch.py | 5 +++-- python/tests/transform_elasticsearch.py | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'python') diff --git a/python/fatcat_tools/workers/elasticsearch.py b/python/fatcat_tools/workers/elasticsearch.py index 91f2796c..f411073d 100644 --- a/python/fatcat_tools/workers/elasticsearch.py +++ b/python/fatcat_tools/workers/elasticsearch.py @@ -113,13 +113,14 @@ class ElasticsearchReleaseWorker(FatcatWorker): for msg in batch: json_str = msg.value().decode('utf-8') entity = entity_from_json(json_str, self.entity_type, api_client=ac) + assert isinstance(entity, self.entity_type) if self.entity_type == ChangelogEntry: key = entity.index # might need to fetch from API - if not (entity.editgroup and entity.editgroup.editor): + if not (entity.editgroup and entity.editgroup.editor): # pylint: disable=no-member # (TODO) entity = api.get_changelog_entry(entity.index) else: - key = entity.ident + key = entity.ident # pylint: disable=no-member # (TODO) if self.entity_type != ChangelogEntry and entity.state == 'wip': print(f"WARNING: skipping state=wip entity: {self.entity_type.__name__} {entity.ident}", file=sys.stderr) diff --git a/python/tests/transform_elasticsearch.py b/python/tests/transform_elasticsearch.py index b9011892..c11c5972 100644 --- a/python/tests/transform_elasticsearch.py +++ b/python/tests/transform_elasticsearch.py @@ -204,15 +204,21 @@ def test_elasticsearch_container_transform(journal_metadata_importer): def test_elasticsearch_file_transform(): - f = entity_from_json(open('./tests/files/file_bcah4zp5tvdhjl5bqci2c2lgfa.json', 'r').read(), FileEntity) - - f.state = 'active' - es = file_to_elasticsearch(f) - assert es['sha1'] == f.sha1 - assert es['sha256'] == f.sha256 - assert es['md5'] == f.md5 - assert es['size_bytes'] == f.size - assert es['mimetype'] == f.mimetype + + with open('./tests/files/file_bcah4zp5tvdhjl5bqci2c2lgfa.json', 'r') as f: + json_str = f.read() + + fe = entity_from_json(json_str, FileEntity) + + fe.state = 'active' + es = file_to_elasticsearch(fe) + + # pylint infers type of 'fe' incorrectly for some reason (as str/bytes) + assert es['sha1'] == fe.sha1 # pylint: disable=no-member + assert es['sha256'] == fe.sha256 # pylint: disable=no-member + assert es['md5'] == fe.md5 # pylint: disable=no-member + assert es['size_bytes'] == fe.size # pylint: disable=no-member + assert es['mimetype'] == fe.mimetype # pylint: disable=no-member assert es['in_ia'] == True assert 'web' in es['rels'] -- cgit v1.2.3