Skip to content

Commit

Permalink
Merge pull request #27 from lfoppiano/test-tests
Browse files Browse the repository at this point in the history
Enable and fix tests
  • Loading branch information
lfoppiano authored Feb 8, 2024
2 parents 46aa706 + 93404c2 commit c08e73a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# - name: Test with pytest
# run: |
# pytest
- name: Test with pytest
run: |
pytest
docker-build:
needs: [build]
Expand Down
3 changes: 3 additions & 0 deletions tests/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os

TEST_DATA_PATH = os.path.dirname(__file__)
18 changes: 11 additions & 7 deletions tests/test_grobid_processors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os

from bs4 import BeautifulSoup
from document_qa.grobid_processors import get_xml_nodes_body, get_xml_nodes_figures, get_xml_nodes_header
from tests.resources import TEST_DATA_PATH


def test_get_xml_nodes_body_paragraphs():
with open("resources/2312.07559.paragraphs.tei.xml", 'r') as fo:
with open(os.path.join(TEST_DATA_PATH, "2312.07559.paragraphs.tei.xml"), 'r') as fo:
soup = BeautifulSoup(fo, 'xml')

nodes = get_xml_nodes_body(soup, use_paragraphs=True)
Expand All @@ -12,7 +15,7 @@ def test_get_xml_nodes_body_paragraphs():


def test_get_xml_nodes_body_sentences():
with open("resources/2312.07559.sentences.tei.xml", 'r') as fo:
with open(os.path.join(TEST_DATA_PATH, "2312.07559.sentences.tei.xml"), 'r') as fo:
soup = BeautifulSoup(fo, 'xml')

children = get_xml_nodes_body(soup, use_paragraphs=False)
Expand All @@ -21,7 +24,7 @@ def test_get_xml_nodes_body_sentences():


def test_get_xml_nodes_figures():
with open("resources/2312.07559.paragraphs.tei.xml", 'r') as fo:
with open(os.path.join(TEST_DATA_PATH, "2312.07559.paragraphs.tei.xml"), 'r') as fo:
soup = BeautifulSoup(fo, 'xml')

children = get_xml_nodes_figures(soup)
Expand All @@ -30,17 +33,18 @@ def test_get_xml_nodes_figures():


def test_get_xml_nodes_header_paragraphs():
with open("resources/2312.07559.paragraphs.tei.xml", 'r') as fo:
with open(os.path.join(TEST_DATA_PATH, "2312.07559.paragraphs.tei.xml"), 'r') as fo:
soup = BeautifulSoup(fo, 'xml')

children = get_xml_nodes_header(soup)

assert len(children) == 8
assert sum([len(child) for k, child in children.items()]) == 8


def test_get_xml_nodes_header_sentences():
with open("resources/2312.07559.sentences.tei.xml", 'r') as fo:
with open(os.path.join(TEST_DATA_PATH, "2312.07559.sentences.tei.xml"), 'r') as fo:
soup = BeautifulSoup(fo, 'xml')

children = get_xml_nodes_header(soup, use_paragraphs=False)

assert len(children) == 15
assert sum([len(child) for k, child in children.items()]) == 15

0 comments on commit c08e73a

Please sign in to comment.