aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/files/example_ungrobided.tsv20
-rw-r--r--python/tests/test_backfill_hbase_from_cdx.py74
-rw-r--r--python/tests/test_extraction_cdx_grobid.py319
-rw-r--r--python/tests/test_extraction_ungrobided.py178
4 files changed, 0 insertions, 591 deletions
diff --git a/python/tests/files/example_ungrobided.tsv b/python/tests/files/example_ungrobided.tsv
deleted file mode 100644
index 9263b6f..0000000
--- a/python/tests/files/example_ungrobided.tsv
+++ /dev/null
@@ -1,20 +0,0 @@
-sha1:23LOSW2QVMKUYXPFZBXQHBBNQR45WTMU {"c": 1, "d": "2017-10-27T22:21:13", "f": "PDFS-20171027214658-00155.warc.gz", "o": 984263791, "u": "http://circ.ahajournals.org/content/circulationaha/53/6/965.full.pdf"} application/pdf {"c_size": 1050532, "dt": "20171027222113", "offset": 984263791, "surt": "org,ahajournals,circ)/content/circulationaha/53/6/965.full.pdf", "url": "http://circ.ahajournals.org/content/circulationaha/53/6/965.full.pdf", "warc": "PDFS-20171027125450-crawl815/PDFS-20171027214658-00155.warc.gz"}
-sha1:23M2N262M5TWB7F3BVB6ESD3Q26SMPFA {"c": 1, "d": "2012-09-29T07:05:16", "f": "ARCHIVEIT-219-QUARTERLY-FWGZDI-20120929065657-00119-crawling203.us.archive.org-6680.warc.gz", "o": 83570746, "u": "https://www.indiana.edu/~orafaq/faq/pdf.php?cat=37&id=225&artlang=en"} application/pdf {"c_size": 3590, "dt": "20120929070516", "offset": 83570746, "surt": "edu,indiana)/~orafaq/faq/pdf.php?artlang=en&cat=37&id=225", "url": "https://www.indiana.edu/~orafaq/faq/pdf.php?cat=37&id=225&artlang=en", "warc": "ARCHIVEIT-219-QUARTERLY-FWGZDI-00001/ARCHIVEIT-219-QUARTERLY-FWGZDI-20120929065657-00119-crawling203.us.archive.org-6680.warc.gz"}
-sha1:23MFQLDGP4WJD67BS7ERMYQUF7TGCG5X {"c": 1, "d": "2017-08-25T15:19:28", "f": "MSAG-PDF-CRAWL-2017-08-04-20170825143335512-08107-3480~wbgrp-svc284.us.archive.org~8443.warc.gz", "o": 573475485, "u": "http://www.bloodjournal.org/content/bloodjournal/77/7/1484.full.pdf?sso-checked=true"} application/pdf {"c_size": 3411470, "dt": "20170825151928", "offset": 573475485, "surt": "org,bloodjournal)/content/bloodjournal/77/7/1484.full.pdf?sso-checked=true", "url": "http://www.bloodjournal.org/content/bloodjournal/77/7/1484.full.pdf?sso-checked=true", "warc": "MSAG-PDF-CRAWL-2017-08-04-20170825114428485-08102-08111-wbgrp-svc284/MSAG-PDF-CRAWL-2017-08-04-20170825143335512-08107-3480~wbgrp-svc284.us.archive.org~8443.warc.gz"}
-sha1:23MG6K5Z3JENYCZ2OGTNOJ7QPYANJRCZ {"c": 1, "d": "2017-10-10T11:29:50", "f": "PDFS-20171010110639-00278.warc.gz", "o": 665222706, "u": "http://circ.ahajournals.org/content/circulationaha/53/5/797.full.pdf?download=true"} application/pdf {"c_size": 1107121, "dt": "20171010112950", "offset": 665222706, "surt": "org,ahajournals,circ)/content/circulationaha/53/5/797.full.pdf?download=true", "url": "http://circ.ahajournals.org/content/circulationaha/53/5/797.full.pdf?download=true", "warc": "PDFS-20171010110639-crawl815/PDFS-20171010110639-00278.warc.gz"}
-sha1:23MN67JQKDWRUXJMXXJ2GX6O43SQIV76 {"c": 1, "d": "2015-06-06T18:17:08", "f": "ARCHIVEIT-219-QUARTERLY-9582-20150606125000169-00071-wbgrp-crawl067.us.archive.org-6440.warc.gz", "o": 603211220, "u": "https://www.indiana.edu/~orafaq/faq/pdf.php?cat=36&id=95&artlang=en"} application/pdf {"c_size": 3450, "dt": "20150606181708", "offset": 603211220, "surt": "edu,indiana)/~orafaq/faq/pdf.php?artlang=en&cat=36&id=95", "url": "https://www.indiana.edu/~orafaq/faq/pdf.php?cat=36&id=95&artlang=en", "warc": "ARCHIVEIT-219-QUARTERLY-9582-00007/ARCHIVEIT-219-QUARTERLY-9582-20150606125000169-00071-wbgrp-crawl067.us.archive.org-6440.warc.gz"}
-sha1:23MQCEOMQS5SMZCXIPNQ4E3ZKOCF6DIM {"c": 1, "d": "2004-01-02T19:45:22", "f": "DU_crawl10.20040102194453.arc.gz", "o": 38062592, "u": "http://www.csupomona.edu:80/~darsadmin/ACTIONITEMS.pdf"} application/pdf {"c_size": 15406, "dt": "20040102194522", "offset": 38062592, "surt": "edu,csupomona)/~darsadmin/actionitems.pdf", "url": "http://www.csupomona.edu:80/~darsadmin/ACTIONITEMS.pdf", "warc": "DU_crawl10.20040102181929-c/DU_crawl10.20040102194453.arc.gz"}
-sha1:23NKO4TW6XCESXMSUOOICI3AXVK6Z5BL {"c": 1, "d": "2015-04-27T11:16:33", "f": "eric.ed.gov-inf-20150409-030712-1648j-00064.warc.gz", "o": 3872820483, "u": "http://files.eric.ed.gov/fulltext/ED088632.pdf"} application/pdf {"c_size": 2223528, "dt": "20150427111633", "offset": 3872820483, "surt": "gov,ed,eric,files)/fulltext/ed088632.pdf", "url": "http://files.eric.ed.gov/fulltext/ED088632.pdf", "warc": "archiveteam_archivebot_go_20150427150006/eric.ed.gov-inf-20150409-030712-1648j-00064.warc.gz"}
-sha1:23NW2EPLXDA6UBIJLQMM2DJ2K3GL3WTB {"c": 1, "d": "2014-08-13T09:04:30", "f": "WIDE-20140813084304-09684.warc.gz", "o": 726289594, "u": "http://research.sdccd.edu/docs/Accreditation/2012%20Surveys/Employee%20-%20Briefing/Mesa%20College%202012%20Employee%20Feedback%20Survey%20Briefing.pdf"} application/pdf {"c_size": 3472527, "dt": "20140813090430", "offset": 726289594, "surt": "edu,sdccd,research)/docs/accreditation/2012%20surveys/employee%20-%20briefing/mesa%20college%202012%20employee%20feedback%20survey%20briefing.pdf", "url": "http://research.sdccd.edu/docs/Accreditation/2012%20Surveys/Employee%20-%20Briefing/Mesa%20College%202012%20Employee%20Feedback%20Survey%20Briefing.pdf", "warc": "WIDE-20140813074743-crawl424/WIDE-20140813084304-09684.warc.gz"}
-sha1:23OQICQ4IBVNHJBWJX5ON3QR26KNMQNT {"c": 1, "d": "2010-06-29T00:35:17", "f": "EDG-20100628234135-01241-ia360918.us.archive.org.warc.gz", "o": 572430160, "u": "http://journalism.arizona.edu/news/rockypt6.pdf"} application/pdf {"c_size": 194706, "dt": "20100629003517", "offset": 572430160, "surt": "edu,arizona,journalism)/news/rockypt6.pdf", "url": "http://journalism.arizona.edu/news/rockypt6.pdf", "warc": "EDG-20100628214935-01235-01243-ia360918-20100629023741-00000/EDG-20100628234135-01241-ia360918.us.archive.org.warc.gz"}
-sha1:23OT2AAYPJ3Z5ZOQXVJJTVTKY6QUPICI {"c": 1, "d": "2007-02-25T17:49:01", "f": "38_0_20070225174831_crawl28.arc.gz", "o": 93868066, "u": "http://www.ece.tufts.edu:80/~hopwood/tampa-proceedings.pdf"} application/pdf {"c_size": 162157, "dt": "20070225174901", "offset": 93868066, "surt": "edu,tufts,ece)/~hopwood/tampa-proceedings.pdf", "url": "http://www.ece.tufts.edu:80/~hopwood/tampa-proceedings.pdf", "warc": "38_0_20070225173722_crawl28-c/38_0_20070225174831_crawl28.arc.gz"}
-sha1:23OUFX3ZYMF53HY4RUONR5PKN4HXN4O3 {"c": 1, "d": "2004-05-26T06:45:34", "f": "DW_crawl10.20040526064432.arc.gz", "o": 67593910, "u": "http://207.36.165.114:80/NewOrleans/Papers/1301466.pdf"} application/pdf {"c_size": 306879, "dt": "20040526064534", "offset": 67593910, "surt": "114,165,36,207)/neworleans/papers/1301466.pdf", "url": "http://207.36.165.114:80/NewOrleans/Papers/1301466.pdf", "warc": "DW_crawl10.20040525230808-c/DW_crawl10.20040526064432.arc.gz"}
-sha1:23PA23UIWCBA3CSTDK2JYX7ZIVOHULFG {"c": 1, "d": "2016-02-05T21:48:33", "f": "NLNZ-NZ-CRAWL-005-20160205211003375-02839-6291~wbgrp-crawl007.us.archive.org~8443.warc.gz", "o": 630386943, "u": "http://homepages.engineering.auckland.ac.nz/~smohan/Outreach/Docs/2013/TTU_REU2013.pdf"} application/pdf {"c_size": 2979614, "dt": "20160205214833", "offset": 630386943, "surt": "nz,ac,auckland,engineering,homepages)/~smohan/outreach/docs/2013/ttu_reu2013.pdf", "url": "http://homepages.engineering.auckland.ac.nz/~smohan/Outreach/Docs/2013/TTU_REU2013.pdf", "warc": "NLNZ-NZ-CRAWL-005-20160205211003375-02839-02848-wbgrp-crawl007/NLNZ-NZ-CRAWL-005-20160205211003375-02839-6291~wbgrp-crawl007.us.archive.org~8443.warc.gz"}
-sha1:23PGC74CTD7P6PCF3MZZZJMPYFXRK3OB {"c": 1, "d": "2005-03-17T15:05:51", "f": "EC_binary1_crawl30.20050317150502.arc.gz", "o": 75675778, "u": "http://www.csupomona.edu:80/%7Eengineering/programs/courses/aro/course_outlines/aro_407.pdf"} application/pdf {"c_size": 4842, "dt": "20050317150551", "offset": 75675778, "surt": "edu,csupomona)/~engineering/programs/courses/aro/course_outlines/aro_407.pdf", "url": "http://www.csupomona.edu:80/%7Eengineering/programs/courses/aro/course_outlines/aro_407.pdf", "warc": "EC_binary1_crawl30.20050317135651-c/EC_binary1_crawl30.20050317150502.arc.gz"}
-sha1:23PKJEQWUJAIQQSLP3GCCC5VDXN4RFCX {"c": 1, "d": "2017-10-10T23:50:37", "f": "WIDE-20171010214240-16560.warc.gz", "o": 962106404, "u": "http://www.nbrb.by/bv/articles/8997.pdf"} application/pdf {"c_size": 273375, "dt": "20171010235037", "offset": 962106404, "surt": "by,nbrb)/bv/articles/8997.pdf", "url": "http://www.nbrb.by/bv/articles/8997.pdf", "warc": "WIDE-20171010202419-crawl424/WIDE-20171010214240-16560.warc.gz"}
-sha1:23PRILJUIQUKHRYQIUYAKSBFPH53FOGT {"c": 1, "d": "2017-07-14T18:51:38", "f": "WIDE-20170714181144-06521.warc.gz", "o": 820382225, "u": "http://carsandracingstuff.com/library/articles/32538.pdf"} application/pdf {"c_size": 125426, "dt": "20170714185138", "offset": 820382225, "surt": "com,carsandracingstuff)/library/articles/32538.pdf", "url": "http://carsandracingstuff.com/library/articles/32538.pdf", "warc": "WIDE-20170714174218-crawl426/WIDE-20170714181144-06521.warc.gz"}
-sha1:23PTUXWSNSVE4HS5J7ELDUUG63J2FPCI {"c": 1, "d": "2016-06-09T00:27:36", "f": "WIDE-20160609001810-06993.warc.gz", "o": 287880616, "u": "http://www.case-research.eu/sites/default/files/publications/18092393_E-brief_Dabrowski_Monetary_Policy_final_0.pdf"} application/pdf {"c_size": 68262, "dt": "20160609002736", "offset": 287880616, "surt": "eu,case-research)/sites/default/files/publications/18092393_e-brief_dabrowski_monetary_policy_final_0.pdf", "url": "http://www.case-research.eu/sites/default/files/publications/18092393_E-brief_Dabrowski_Monetary_Policy_final_0.pdf", "warc": "WIDE-20160609000312-crawl427/WIDE-20160609001810-06993.warc.gz"}
-sha1:23PW2APYHNBPIBRIVNQ6TMKUNY53UL3D {"c": 1, "d": "2016-01-07T03:29:03", "f": "MUSEUM-20160107025230-02354.warc.gz", "o": 413484441, "u": "http://www.portlandoregon.gov/fire/article/363695"} application/pdf {"c_size": 44600, "dt": "20160107032903", "offset": 413484441, "surt": "gov,portlandoregon)/fire/article/363695", "url": "http://www.portlandoregon.gov/fire/article/363695", "warc": "MUSEUM-20160107004301-crawl891/MUSEUM-20160107025230-02354.warc.gz"}
-sha1:23RJIHUIOYY5747CR6YYCTMACXDCFYTT {"c": 1, "d": "2014-06-07T18:00:56", "f": "ARCHIVEIT-219-QUARTERLY-20047-20140607125555378-00017-wbgrp-crawl051.us.archive.org-6442.warc.gz", "o": 720590380, "u": "https://www.indiana.edu/~orafaq/faq/pdf.php?cat=36&id=264&artlang=en"} application/pdf {"c_size": 3727, "dt": "20140607180056", "offset": 720590380, "surt": "edu,indiana)/~orafaq/faq/pdf.php?artlang=en&cat=36&id=264", "url": "https://www.indiana.edu/~orafaq/faq/pdf.php?cat=36&id=264&artlang=en", "warc": "ARCHIVEIT-219-QUARTERLY-20047-00001/ARCHIVEIT-219-QUARTERLY-20047-20140607125555378-00017-wbgrp-crawl051.us.archive.org-6442.warc.gz"}
-sha1:23SMLYPFEGIRV6M37FJ5D364TXQXCSMR {"c": 1, "d": "2011-07-12T22:20:32", "f": "WIDE-20110712221302-03146.warc.gz", "o": 222089710, "u": "http://media.dailyuw.com/papers/_091030_7-14_color_web.pdf"} application/pdf {"c_size": 4654708, "dt": "20110712222032", "offset": 222089710, "surt": "com,dailyuw,media)/papers/_091030_7-14_color_web.pdf", "url": "http://media.dailyuw.com/papers/_091030_7-14_color_web.pdf", "warc": "WIDE-20110712221302-crawl413/WIDE-20110712221302-03146.warc.gz"}
-sha1:23SN4XBPSCRPRIHH5UAV45LFCP3VDV3V {"c": 1, "d": "2010-10-28T09:03:57", "f": "WIDE-20101028084449158-00409-23450~ia360921.us.archive.org~9443.warc.gz", "o": 756726028, "u": "http://cdacnoida.in/ASCNT-2010/Language%20Technology/Paper/Reducing%20Errors%20in%20Translation%20using%20Pre-editor%20for%20Indian%20English%20Sentences.pdf"} application/pdf {"c_size": 98408, "dt": "20101028090357", "offset": 756726028, "surt": "in,cdacnoida)/ascnt-2010/language%20technology/paper/reducing%20errors%20in%20translation%20using%20pre-editor%20for%20indian%20english%20sentences.pdf", "url": "http://cdacnoida.in/ASCNT-2010/Language%20Technology/Paper/Reducing%20Errors%20in%20Translation%20using%20Pre-editor%20for%20Indian%20English%20Sentences.pdf", "warc": "WIDE-20101028063239344-00397-00415-ia360921/WIDE-20101028084449158-00409-23450~ia360921.us.archive.org~9443.warc.gz"}
diff --git a/python/tests/test_backfill_hbase_from_cdx.py b/python/tests/test_backfill_hbase_from_cdx.py
deleted file mode 100644
index 070662b..0000000
--- a/python/tests/test_backfill_hbase_from_cdx.py
+++ /dev/null
@@ -1,74 +0,0 @@
-"""
-TODO: could probably refactor to use unittest.mock.patch('happybase')
-"""
-
-import io
-import json
-import pytest
-import mrjob
-import happybase_mock
-from backfill_hbase_from_cdx import MRCDXBackfillHBase
-
-@pytest.fixture
-def job():
- """
- Note: this mock only seems to work with job.run_mapper(), not job.run();
- the later results in a separate instantiation without the mock?
- """
- job = MRCDXBackfillHBase(['--no-conf', '-'])
-
- conn = happybase_mock.Connection()
- conn.create_table('wbgrp-journal-extract-test',
- {'file': {}, 'grobid0': {}, 'f': {}})
- job.hb_table = conn.table('wbgrp-journal-extract-test')
-
- return job
-
-
-def test_some_lines(job):
-
- raw = io.BytesIO(b"""
-com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 301 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz
-eu,eui,cadmus)/bitstream/handle/1814/36635/rscas_2015_03.pdf;jsessionid=761393014319a39f40d32ae3eb3a853f?sequence=1 20170705062202 http://cadmus.eui.eu/bitstream/handle/1814/36635/RSCAS_2015_03.pdf%3Bjsessionid%3D761393014319A39F40D32AE3EB3A853F?sequence%3D1 application/PDF 200 MPCXVWMUTRUGFP36SLPHKDLY6NGU4S3J - - 854156 328850624 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz
-com,pbworks,educ333b)/robots.txt 20170705063311 http://educ333b.pbworks.com/robots.txt text/plain 200 6VAUYENMOU2SK2OWNRPDD6WTQTECGZAD - - 638 398190140 CITESEERX-CRAWL-2017-06-20-20170705062707827-00049-00058-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705063158203-00053-31209~wbgrp-svc284.us.archive.org~8443.warc.gz
-""")
-
- job.sandbox(stdin=raw)
- job.run_mapper()
-
- assert job.hb_table.row(b'1') == {}
- # HTTP 301
- assert job.hb_table.row(b'sha1:3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ') == {}
- # valid
- assert job.hb_table.row(b'sha1:MPCXVWMUTRUGFP36SLPHKDLY6NGU4S3J') != {}
- # text/plain
- assert job.hb_table.row(b'sha1:6VAUYENMOU2SK2OWNRPDD6WTQTECGZAD') == {}
-
- row = job.hb_table.row(b'sha1:MPCXVWMUTRUGFP36SLPHKDLY6NGU4S3J')
- assert row[b'file:mime'] == b"application/pdf"
-
- file_cdx = json.loads(row[b'file:cdx'].decode('utf-8'))
- assert int(file_cdx['offset']) == 328850624
-
- f_c = json.loads(row[b'f:c'].decode('utf-8'))
- assert f_c['u'] == "http://cadmus.eui.eu/bitstream/handle/1814/36635/RSCAS_2015_03.pdf%3Bjsessionid%3D761393014319A39F40D32AE3EB3A853F?sequence%3D1"
- assert b'i' not in f_c
-
-def test_parse_cdx_skip(job):
-
- job.mapper_init()
-
- print("CDX prefix")
- raw = " com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 200 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.mapper(None, raw).__next__()
- assert info is None
- assert status['status'] == "invalid"
- assert 'prefix' in status['reason']
-
- print("mimetype")
- raw = "com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf text/html 200 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.mapper(None, raw).__next__()
- assert info is None
- assert status['status'] == "skip"
- assert 'mimetype' in status['reason']
-
diff --git a/python/tests/test_extraction_cdx_grobid.py b/python/tests/test_extraction_cdx_grobid.py
deleted file mode 100644
index 471d94a..0000000
--- a/python/tests/test_extraction_cdx_grobid.py
+++ /dev/null
@@ -1,319 +0,0 @@
-
-import io
-import json
-import mrjob
-import pytest
-import struct
-import responses
-import happybase_mock
-import wayback.exception
-from unittest import mock
-from extraction_cdx_grobid import MRExtractCdxGrobid
-
-
-FAKE_PDF_BYTES = b"%PDF SOME JUNK" + struct.pack("!q", 112853843)
-OK_CDX_LINE = b"""com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 200 ABCDEF12345Q2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"""
-
-with open('tests/files/23b29ea36382680716be08fc71aa81bd226e8a85.xml', 'r') as f:
- REAL_TEI_XML = f.read()
-
-@pytest.fixture
-def job():
- """
- Note: this mock only seems to work with job.run_mapper(), not job.run();
- the later results in a separate instantiation without the mock?
- """
- job = MRExtractCdxGrobid(['--no-conf', '-'])
-
- conn = happybase_mock.Connection()
- conn.create_table('wbgrp-journal-extract-test',
- {'file': {}, 'grobid0': {}, 'f': {}})
- job.hb_table = conn.table('wbgrp-journal-extract-test')
-
- return job
-
-
-@mock.patch('extraction_cdx_grobid.MRExtractCdxGrobid.fetch_warc_content', return_value=(FAKE_PDF_BYTES, None))
-@responses.activate
-def test_mapper_lines(mock_fetch, job):
-
- responses.add(responses.POST, 'http://localhost:8070/api/processFulltextDocument', status=200,
- body=REAL_TEI_XML, content_type='text/xml')
-
- raw = io.BytesIO(b"""
-com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 301 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz
-eu,eui,cadmus)/bitstream/handle/1814/36635/rscas_2015_03.pdf;jsessionid=761393014319a39f40d32ae3eb3a853f?sequence=1 20170705062202 http://cadmus.eui.eu/bitstream/handle/1814/36635/RSCAS_2015_03.pdf%3Bjsessionid%3D761393014319A39F40D32AE3EB3A853F?sequence%3D1 application/PDF 200 MPCXVWMUTRUGFP36SLPHKDLY6NGU4S3J - - 854156 328850624 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz
-com,pbworks,educ333b)/robots.txt 20170705063311 http://educ333b.pbworks.com/robots.txt text/plain 200 6VAUYENMOU2SK2OWNRPDD6WTQTECGZAD - - 638 398190140 CITESEERX-CRAWL-2017-06-20-20170705062707827-00049-00058-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705063158203-00053-31209~wbgrp-svc284.us.archive.org~8443.warc.gz
-""")
-
- output = io.BytesIO()
- job.sandbox(stdin=raw, stdout=output)
-
- job.run_mapper()
-
- # for debugging tests
- #print(output.getvalue().decode('utf-8'))
- #print(list(job.hb_table.scan()))
-
- # wayback gets FETCH 1x times
- mock_fetch.assert_called_once_with(
- "CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz",
- 328850624,
- 854156)
-
- # grobid gets POST 1x times
- assert len(responses.calls) == 1
-
- # HBase
- assert job.hb_table.row(b'1') == {}
- # HTTP 301
- assert job.hb_table.row(b'sha1:3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ') == {}
- # valid
- assert job.hb_table.row(b'sha1:MPCXVWMUTRUGFP36SLPHKDLY6NGU4S3J') != {}
- # text/plain
- assert job.hb_table.row(b'sha1:6VAUYENMOU2SK2OWNRPDD6WTQTECGZAD') == {}
-
- # Saved extraction info
- row = job.hb_table.row(b'sha1:MPCXVWMUTRUGFP36SLPHKDLY6NGU4S3J')
-
- assert struct.unpack("!q", row[b'file:size'])[0] == len(FAKE_PDF_BYTES)
- assert row[b'file:mime'] == b"application/pdf"
- assert struct.unpack("!q", row[b'grobid0:status_code'])[0] == 200
- # TODO: assert row[b'grobid0:quality'] == None
- status = json.loads(row[b'grobid0:status'].decode('utf-8'))
- assert type(status) == type(dict())
- assert row[b'grobid0:tei_xml'].decode('utf-8') == REAL_TEI_XML
- tei_json = json.loads(row[b'grobid0:tei_json'].decode('utf-8'))
- metadata = json.loads(row[b'grobid0:metadata'].decode('utf-8'))
- assert tei_json['title'] == metadata['title']
- assert 'body' in tei_json
- assert 'body' not in metadata
-
-def test_parse_cdx_invalid(job):
-
- print("valid")
- raw = "com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 200 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.parse_line(raw)
- assert status is None
-
- print("space-prefixed line")
- raw = " com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 200 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.parse_line(raw)
- assert info is None
- assert status['status'] == "invalid"
- assert 'prefix' in status['reason']
-
- print("commented line")
- raw = "#com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 200 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.parse_line(raw)
- assert info is None
- assert status['status'] == "invalid"
- assert 'prefix' in status['reason']
-
- print("wrong column count")
- raw = "a b c d"
- info, status = job.parse_line(raw)
- assert info is None
- assert status['status'] == "invalid"
- assert 'parse' in status['reason']
-
- print("missing mimetype")
- raw = "com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf - 200 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.parse_line(raw)
- assert info is None
- print(status)
- assert status['status'] == "invalid"
- assert 'parse' in status['reason']
-
- print("HTTP status")
- raw = "com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 501 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.parse_line(raw)
- assert info is None
- assert status['status'] == "invalid"
-
- print("datetime")
- raw = "com,sagepub,cep)/content/28/9/960.full.pdf 20170705 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 501 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.parse_line(raw)
- assert info is None
- assert status['status'] == "invalid"
-
-
-def test_parse_cdx_skip(job):
-
- job.mapper_init()
-
- print("warc format")
- raw = "com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 200 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.mapper(None, raw).__next__()
- assert info is None
- assert status['status'] == "skip"
- assert 'WARC' in status['reason']
-
- print("mimetype")
- raw = "com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf text/html 200 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.mapper(None, raw).__next__()
- assert info is None
- assert status['status'] == "skip"
- assert 'mimetype' in status['reason']
-
-
-@mock.patch('extraction_cdx_grobid.MRExtractCdxGrobid.fetch_warc_content', return_value=(FAKE_PDF_BYTES, None))
-@responses.activate
-def test_grobid_503(mock_fetch, job):
-
- status = b'{"status": "done broke due to 503"}'
- responses.add(responses.POST, 'http://localhost:8070/api/processFulltextDocument', status=503,
- body=status)
-
- output = io.BytesIO()
- job.sandbox(stdin=io.BytesIO(OK_CDX_LINE), stdout=output)
- job.run_mapper()
- row = job.hb_table.row(b'sha1:ABCDEF12345Q2MSVX7XZKYAYSCX5QBYJ')
- status = json.loads(row[b'grobid0:status'].decode('utf-8'))
- assert json.loads(row[b'grobid0:status'].decode('utf-8')) == status
-
-
-@mock.patch('extraction_cdx_grobid.MRExtractCdxGrobid.fetch_warc_content', return_value=(FAKE_PDF_BYTES, None))
-@responses.activate
-def test_grobid_not_xml(mock_fetch, job):
-
- payload = b'this is not XML'
- responses.add(responses.POST, 'http://localhost:8070/api/processFulltextDocument', status=200,
- body=payload)
-
- output = io.BytesIO()
- job.sandbox(stdin=io.BytesIO(OK_CDX_LINE), stdout=output)
- job.run_mapper()
- output = output.getvalue().decode('utf-8')
- row = job.hb_table.row(b'sha1:ABCDEF12345Q2MSVX7XZKYAYSCX5QBYJ')
- assert struct.unpack("!q", row[b'grobid0:status_code'])[0] == 200
- assert row[b'grobid0:tei_xml'] == payload
- assert b'grobid0:tei_json' not in row
- assert "XML parse error" in output
-
-
-@mock.patch('extraction_cdx_grobid.MRExtractCdxGrobid.fetch_warc_content', return_value=(FAKE_PDF_BYTES, None))
-@responses.activate
-def test_grobid_not_tei(mock_fetch, job):
-
- payload = b'<xml></xml>'
- responses.add(responses.POST, 'http://localhost:8070/api/processFulltextDocument', status=200,
- body=payload)
-
- output = io.BytesIO()
- job.sandbox(stdin=io.BytesIO(OK_CDX_LINE), stdout=output)
- job.run_mapper()
- output = output.getvalue().decode('utf-8')
- row = job.hb_table.row(b'sha1:ABCDEF12345Q2MSVX7XZKYAYSCX5QBYJ')
- assert struct.unpack("!q", row[b'grobid0:status_code'])[0] == 200
- assert row[b'grobid0:tei_xml'] == payload
- assert b'grobid0:tei_json' not in row
- assert "non-TEI content" in output
-
-
-@mock.patch('extraction_cdx_grobid.MRExtractCdxGrobid.fetch_warc_content', return_value=(FAKE_PDF_BYTES, None))
-def test_grobid_invalid_connection(mock_fetch, job):
-
- status = b'{"status": "done broke"}'
- job.options.grobid_uri = 'http://host.invalid:8070/api/processFulltextDocument'
-
- output = io.BytesIO()
- job.sandbox(stdin=io.BytesIO(OK_CDX_LINE), stdout=output)
- job.run_mapper()
- output = output.getvalue().decode('utf-8')
- assert 'error' in output
- assert 'GROBID' in output
- assert job.hb_table.row(b'sha1:ABCDEF12345Q2MSVX7XZKYAYSCX5QBYJ') == {}
-
-
-def test_wayback_failure(job):
-
- job.options.warc_uri_prefix = 'http://host.invalid/'
-
- output = io.BytesIO()
- job.sandbox(stdin=io.BytesIO(OK_CDX_LINE), stdout=output)
- job.run_mapper()
- output = output.getvalue().decode('utf-8')
- assert 'error' in output
- assert 'wayback' in output
- assert job.hb_table.row(b'sha1:ABCDEF12345Q2MSVX7XZKYAYSCX5QBYJ') == {}
-
-
-@mock.patch('extraction_cdx_grobid.ResourceStore')
-def test_wayback_not_found(mock_rs, job):
-
- # This is... a little convoluded. Basically creating a 404 situation for
- # reading a wayback resource.
- mock_resource = mock.MagicMock()
- mock_resource.get_status.return_value = (404, "Not Found")
- mock_rso = mock.MagicMock()
- mock_rso.load_resource.return_value = mock_resource
- mock_rs.return_value = mock_rso
- print(mock_rs().load_resource().get_status())
-
- job.options.warc_uri_prefix = 'http://dummy-archive.org/'
-
- output = io.BytesIO()
- job.sandbox(stdin=io.BytesIO(OK_CDX_LINE), stdout=output)
- job.run_mapper()
- output = output.getvalue().decode('utf-8')
-
- print(output)
- assert 'error' in output
- assert 'not 200' in output
- assert job.hb_table.row(b'sha1:ABCDEF12345Q2MSVX7XZKYAYSCX5QBYJ') == {}
-
-
-@mock.patch('extraction_cdx_grobid.MRExtractCdxGrobid.fetch_warc_content', return_value=(FAKE_PDF_BYTES, None))
-@responses.activate
-def test_mapper_rerun(mock_fetch, job):
-
- responses.add(responses.POST, 'http://localhost:8070/api/processFulltextDocument', status=200,
- body=REAL_TEI_XML, content_type='text/xml')
-
- output1 = io.BytesIO()
- job.sandbox(stdin=io.BytesIO(OK_CDX_LINE), stdout=output1)
- job.run_mapper()
- output1 = output1.getvalue().decode('utf-8')
-
- # wayback gets FETCH 1x times
- assert mock_fetch.call_count == 1
- # grobid gets POST 1x times
- assert len(responses.calls) == 1
- # HBase
- assert job.hb_table.row(b'sha1:ABCDEF12345Q2MSVX7XZKYAYSCX5QBYJ') != {}
- assert 'success' in output1
-
- # Run again, same line
- output2 = io.BytesIO()
- job.sandbox(stdin=io.BytesIO(OK_CDX_LINE), stdout=output2)
- job.run_mapper()
- output2 = output2.getvalue().decode('utf-8')
-
- # wayback still only FETCH 1x times
- assert mock_fetch.call_count == 1
- # grobid still only POST 1x times
- assert len(responses.calls) == 1
- assert 'existing' in output2
-
-@mock.patch('extraction_cdx_grobid.MRExtractCdxGrobid.fetch_warc_content', return_value=(FAKE_PDF_BYTES, None))
-@responses.activate
-def test_mapper_previously_backfilled(mock_fetch, job):
-
- responses.add(responses.POST, 'http://localhost:8070/api/processFulltextDocument', status=200,
- body=REAL_TEI_XML, content_type='text/xml')
-
- job.hb_table.put(b'sha1:ABCDEF12345Q2MSVX7XZKYAYSCX5QBYJ',
- {b'f:c': b'{"some": "dict"}', b'file:col': b'bogus'})
- assert job.hb_table.row(b'sha1:ABCDEF12345Q2MSVX7XZKYAYSCX5QBYJ') != {}
-
- output1 = io.BytesIO()
- job.sandbox(stdin=io.BytesIO(OK_CDX_LINE), stdout=output1)
- job.run_mapper()
- output1 = output1.getvalue().decode('utf-8')
-
- # wayback gets FETCH 1x times
- assert mock_fetch.call_count == 1
- # grobid gets POST 1x times
- assert len(responses.calls) == 1
- assert 'success' in output1
diff --git a/python/tests/test_extraction_ungrobided.py b/python/tests/test_extraction_ungrobided.py
deleted file mode 100644
index cb46d29..0000000
--- a/python/tests/test_extraction_ungrobided.py
+++ /dev/null
@@ -1,178 +0,0 @@
-
-import io
-import json
-import mrjob
-import pytest
-import struct
-import responses
-import happybase_mock
-import wayback.exception
-from unittest import mock
-from common import parse_ungrobided_line
-from extraction_ungrobided import MRExtractUnGrobided
-
-
-FAKE_PDF_BYTES = b"%PDF SOME JUNK" + struct.pack("!q", 112853843)
-OK_UNGROBIDED_LINE = b"\t".join((
- b"sha1:3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ",
- b"""{"c": 1, "d": "2017-07-06T07:54:11", "f": "CITESEERX-CRAWL-2017-06-20-20170706075012840-00388-3671~wbgrp-svc285.us.archive.org~8443.warc.gz", "o": 914718776, "u": "http://www.ibc7.org/article/file_down.php?mode%3Darticle_print%26pid%3D250"}""",
- b"application/pdf",
- b"""{"c_size": 501, "dt": "20170706075411", "offset": 914718776, "surt": "org,ibc7)/article/file_down.php?mode=article_print&pid=250", "url": "http://www.ibc7.org/article/file_down.php?mode%3Darticle_print%26pid%3D250", "warc": "CITESEERX-CRAWL-2017-06-20-20170706074206206-00379-00388-wbgrp-svc285/CITESEERX-CRAWL-2017-06-20-20170706075012840-00388-3671~wbgrp-svc285.us.archive.org~8443.warc.gz"}""",
-))
-
-with open('tests/files/23b29ea36382680716be08fc71aa81bd226e8a85.xml', 'r') as f:
- REAL_TEI_XML = f.read()
-
-@pytest.fixture
-def job():
- """
- Note: this mock only seems to work with job.run_mapper(), not job.run();
- the later results in a separate instantiation without the mock?
- """
- job = MRExtractUnGrobided(['--no-conf', '-'])
-
- conn = happybase_mock.Connection()
- conn.create_table('wbgrp-journal-extract-test',
- {'file': {}, 'grobid0': {}, 'f': {}})
- job.hb_table = conn.table('wbgrp-journal-extract-test')
-
- return job
-
-
-@mock.patch('extraction_ungrobided.MRExtractUnGrobided.fetch_warc_content', return_value=(FAKE_PDF_BYTES, None))
-@responses.activate
-def test_mapper_single_line(mock_fetch, job):
-
- responses.add(responses.POST, 'http://localhost:8070/api/processFulltextDocument', status=200,
- body=REAL_TEI_XML, content_type='text/xml')
-
- raw = io.BytesIO(OK_UNGROBIDED_LINE)
-
- output = io.BytesIO()
- job.sandbox(stdin=raw, stdout=output)
-
- job.run_mapper()
-
- # for debugging tests
- #print(output.getvalue().decode('utf-8'))
- #print(list(job.hb_table.scan()))
-
- # wayback gets FETCH 1x times
- mock_fetch.assert_called_once_with(
- "CITESEERX-CRAWL-2017-06-20-20170706074206206-00379-00388-wbgrp-svc285/CITESEERX-CRAWL-2017-06-20-20170706075012840-00388-3671~wbgrp-svc285.us.archive.org~8443.warc.gz",
- 914718776,
- 501)
-
- # grobid gets POST 1x times
- assert len(responses.calls) == 1
-
- # HBase
- assert job.hb_table.row(b'1') == {}
-
- # Saved extraction info
- row = job.hb_table.row(b'sha1:3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ')
-
- assert struct.unpack("!q", row[b'file:size'])[0] == len(FAKE_PDF_BYTES)
- # file:mime should actually not get clobbered by GROBID updater
- #assert row[b'file:mime'] == b"application/pdf"
- assert struct.unpack("!q", row[b'grobid0:status_code'])[0] == 200
- # TODO: assert row[b'grobid0:quality'] == None
- status = json.loads(row[b'grobid0:status'].decode('utf-8'))
- assert type(status) == type(dict())
- assert row[b'grobid0:tei_xml'].decode('utf-8') == REAL_TEI_XML
- tei_json = json.loads(row[b'grobid0:tei_json'].decode('utf-8'))
- metadata = json.loads(row[b'grobid0:metadata'].decode('utf-8'))
- assert tei_json['title'] == metadata['title']
- assert 'body' in tei_json
- assert 'body' not in metadata
-
-@mock.patch('extraction_ungrobided.MRExtractUnGrobided.fetch_warc_content', return_value=(FAKE_PDF_BYTES, None))
-@responses.activate
-def test_mapper_lines(mock_fetch, job):
-
- responses.add(responses.POST, 'http://localhost:8070/api/processFulltextDocument', status=200,
- body=REAL_TEI_XML, content_type='text/xml')
-
- raw = io.BytesIO(b"""sha1:23PTUXWSNSVE4HS5J7ELDUUG63J2FPCI\t{"c": 1, "d": "2016-06-09T00:27:36", "f": "WIDE-20160609001810-06993.warc.gz", "o": 287880616, "u": "http://www.case-research.eu/sites/default/files/publications/18092393_E-brief_Dabrowski_Monetary_Policy_final_0.pdf"}\tapplication/pdf\t{"c_size": 68262, "dt": "20160609002736", "offset": 287880616, "surt": "eu,case-research)/sites/default/files/publications/18092393_e-brief_dabrowski_monetary_policy_final_0.pdf", "url": "http://www.case-research.eu/sites/default/files/publications/18092393_E-brief_Dabrowski_Monetary_Policy_final_0.pdf", "warc": "WIDE-20160609000312-crawl427/WIDE-20160609001810-06993.warc.gz"}
-sha1:23PW2APYHNBPIBRIVNQ6TMKUNY53UL3D\t{"c": 1, "d": "2016-01-07T03:29:03", "f": "MUSEUM-20160107025230-02354.warc.gz", "o": 413484441, "u": "http://www.portlandoregon.gov/fire/article/363695"}\tapplication/pdf\t{"c_size": 44600, "dt": "20160107032903", "offset": 413484441, "surt": "gov,portlandoregon)/fire/article/363695", "url": "http://www.portlandoregon.gov/fire/article/363695", "warc": "MUSEUM-20160107004301-crawl891/MUSEUM-20160107025230-02354.warc.gz"}
-sha1:23RJIHUIOYY5747CR6YYCTMACXDCFYTT\t{"c": 1, "d": "2014-06-07T18:00:56", "f": "ARCHIVEIT-219-QUARTERLY-20047-20140607125555378-00017-wbgrp-crawl051.us.archive.org-6442.warc.gz", "o": 720590380, "u": "https://www.indiana.edu/~orafaq/faq/pdf.php?cat=36&id=264&artlang=en"}\tapplication/pdf\t{"c_size": 3727, "dt": "20140607180056", "offset": 720590380, "surt": "edu,indiana)/~orafaq/faq/pdf.php?artlang=en&cat=36&id=264", "url": "https://www.indiana.edu/~orafaq/faq/pdf.php?cat=36&id=264&artlang=en", "warc": "ARCHIVEIT-219-QUARTERLY-20047-00001/ARCHIVEIT-219-QUARTERLY-20047-20140607125555378-00017-wbgrp-crawl051.us.archive.org-6442.warc.gz"}""")
-
-
- output = io.BytesIO()
- job.sandbox(stdin=raw, stdout=output)
-
- job.run_mapper()
-
- # for debugging tests
- #print(output.getvalue().decode('utf-8'))
- #print(list(job.hb_table.scan()))
-
- # grobid gets POST 3x times
- assert len(responses.calls) == 3
-
- # wayback gets FETCH 3x times
- mock_fetch.assert_has_calls((
- mock.call("WIDE-20160609000312-crawl427/WIDE-20160609001810-06993.warc.gz", 287880616, 68262),
- mock.call("MUSEUM-20160107004301-crawl891/MUSEUM-20160107025230-02354.warc.gz", 413484441, 44600),
- mock.call("ARCHIVEIT-219-QUARTERLY-20047-00001/ARCHIVEIT-219-QUARTERLY-20047-20140607125555378-00017-wbgrp-crawl051.us.archive.org-6442.warc.gz", 720590380, 3727),
- ))
-
- # Saved extraction info
- assert job.hb_table.row(b'sha1:3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ') == {}
- assert job.hb_table.row(b'sha1:23PTUXWSNSVE4HS5J7ELDUUG63J2FPCI') != {}
- assert job.hb_table.row(b'sha1:23PW2APYHNBPIBRIVNQ6TMKUNY53UL3D') != {}
- assert job.hb_table.row(b'sha1:23RJIHUIOYY5747CR6YYCTMACXDCFYTT') != {}
-
- row = job.hb_table.row(b'sha1:23RJIHUIOYY5747CR6YYCTMACXDCFYTT')
- assert struct.unpack("!q", row[b'file:size'])[0] == len(FAKE_PDF_BYTES)
- # file:mime should actually not get clobbered by GROBID updater
- #assert row[b'file:mime'] == b"application/pdf"
- assert struct.unpack("!q", row[b'grobid0:status_code'])[0] == 200
- status = json.loads(row[b'grobid0:status'].decode('utf-8'))
- assert type(status) == type(dict())
- assert row[b'grobid0:tei_xml'].decode('utf-8') == REAL_TEI_XML
- tei_json = json.loads(row[b'grobid0:tei_json'].decode('utf-8'))
- metadata = json.loads(row[b'grobid0:metadata'].decode('utf-8'))
- assert tei_json['title'] == metadata['title']
- assert 'body' in tei_json
- assert 'body' not in metadata
-
-def test_parse_ungrobided_invalid(job):
-
- print("space-prefixed line")
- raw = " com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 200 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.parse_ungrobided_line(raw)
- assert info is None
- assert status['status'] == "invalid"
- assert 'prefix' in status['reason']
-
- print("commented line")
- raw = "#com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf application/pdf 200 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.parse_ungrobided_line(raw)
- assert info is None
- assert status['status'] == "invalid"
- assert 'prefix' in status['reason']
-
- print("wrong column count")
- raw = "a b c d e"
- info, status = job.parse_ungrobided_line(raw)
- assert info is None
- assert status['status'] == "invalid"
- assert 'parse' in status['reason']
-
- print("CDX line, somehow")
- raw = "com,sagepub,cep)/content/28/9/960.full.pdf 20170705062200 http://cep.sagepub.com/content/28/9/960.full.pdf - 200 3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ - - 401 313356621 CITESEERX-CRAWL-2017-06-20-20170705061647307-00039-00048-wbgrp-svc284/CITESEERX-CRAWL-2017-06-20-20170705062052659-00043-31209~wbgrp-svc284.us.archive.org~8443.warc.gz"
- info, status = job.parse_ungrobided_line(raw)
- assert info is None
- print(status)
- assert status['status'] == "invalid"
- assert 'parse' in status['reason']
-
-def test_parse_ungrobided_valid():
-
- parsed = parse_ungrobided_line(OK_UNGROBIDED_LINE.decode('utf-8'))
- assert parsed['key'] == "sha1:3I42H3S6NNFQ2MSVX7XZKYAYSCX5QBYJ"
- assert parsed['f:c']['u'] == "http://www.ibc7.org/article/file_down.php?mode%3Darticle_print%26pid%3D250"
- assert parsed['file:mime'] == "application/pdf"
- assert parsed['file:cdx']['c_size'] == 501
- assert parsed['file:cdx']['dt'] == "20170706075411"