Skip to content

Commit

Permalink
format code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
cneud authored Oct 12, 2023
1 parent 498663b commit dbf7657
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions tests/test_alto_tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Setup sys.path. A bit ugly but avoids setting up setup.py for now.
from pathlib import Path
import sys

sys.path.append(str(Path(__file__).resolve().parents[1]))


Expand All @@ -13,44 +14,49 @@
from src.alto_tools import alto_tools


datadir = os.path.join(str(Path(__file__).resolve().parent), 'data')
datadir = os.path.join(str(Path(__file__).resolve().parent), "data")


def test_alto_parse():
f = open(os.path.join(datadir, 'PPN720183197-PHYS_0004.xml'), 'r', encoding='UTF8')
f = open(os.path.join(datadir, "PPN720183197-PHYS_0004.xml"), "r", encoding="UTF8")
_, xml, xmlns = alto_tools.alto_parse(f)
assert xmlns == 'http://www.loc.gov/standards/alto/ns-v3#'
assert xmlns == "http://www.loc.gov/standards/alto/ns-v3#"


def test_alto_text(capsys):
f = open(os.path.join(datadir, 'PPN720183197-PHYS_0004.xml'), 'r', encoding='UTF8')
f = open(os.path.join(datadir, "PPN720183197-PHYS_0004.xml"), "r", encoding="UTF8")
_, xml, xmlns = alto_tools.alto_parse(f)

alto_tools.alto_text(xml, xmlns)
captured = capsys.readouterr()
assert re.search (r'„Bunte Blätter“', captured.out)
assert re.search (r'Stille Gedanken', captured.out)
assert re.search(r"„Bunte Blätter“", captured.out)
assert re.search(r"Stille Gedanken", captured.out)


def test_walker():
def create_empty_file(fn):
open(fn, 'a').close()
open(fn, "a").close()

with tempfile.TemporaryDirectory() as tmpdirname:
# Create some test files
create_empty_file(os.path.join(tmpdirname, 'test1.xml'))
create_empty_file(os.path.join(tmpdirname, 'test2.xml'))
create_empty_file(os.path.join(tmpdirname, 'this-should-not-be-returned'))
create_empty_file(os.path.join(tmpdirname, "test1.xml"))
create_empty_file(os.path.join(tmpdirname, "test2.xml"))
create_empty_file(os.path.join(tmpdirname, "this-should-not-be-returned"))

# Create a list of inputs
inputs = [
os.path.join(tmpdirname, 'test1.xml'), # Note that this also is in tmpdirname
tmpdirname
os.path.join(
tmpdirname, "test1.xml"
), # Note that this also is in tmpdirname
tmpdirname,
]
fnfilter = lambda fn: fn.endswith('.xml')
fnfilter = lambda fn: fn.endswith(".xml")
expected = [
os.path.join(tmpdirname, 'test1.xml'),
os.path.join(tmpdirname, 'test1.xml'), # second instance from tmpdirname
os.path.join(tmpdirname, 'test2.xml')
# NOT 'this-should-not-be-returned'
os.path.join(tmpdirname, "test1.xml"),
os.path.join(tmpdirname, "test1.xml"), # second instance from tmpdirname
os.path.join(tmpdirname, "test2.xml")
# NOT 'this-should-not-be-returned'
]
assert collections.Counter(alto_tools.walker(inputs, fnfilter)) == collections.Counter(expected)
assert collections.Counter(
alto_tools.walker(inputs, fnfilter)
) == collections.Counter(expected)

0 comments on commit dbf7657

Please sign in to comment.