5c73c40bcc
This is a pretty feature-complete version 1. I don't know why I waited this long to commit anything.
52 lines
1.3 KiB
Python
52 lines
1.3 KiB
Python
import io
|
|
import pathlib
|
|
|
|
import pytest
|
|
from . import DATA_DIR, normalize_whitespace
|
|
|
|
from import2ledger import __main__ as i2lmain
|
|
|
|
ARGLIST = [
|
|
'-C', (DATA_DIR / 'test_main.ini').as_posix(),
|
|
]
|
|
|
|
def run_main(arglist):
|
|
stdout = io.StringIO()
|
|
stderr = io.StringIO()
|
|
exitcode = i2lmain.main(arglist, stdout, stderr)
|
|
stdout.seek(0)
|
|
stderr.seek(0)
|
|
return exitcode, stdout, stderr
|
|
|
|
def iter_entries(in_file):
|
|
lines = []
|
|
for line in in_file:
|
|
if line == '\n':
|
|
if lines:
|
|
yield ''.join(lines)
|
|
lines = []
|
|
else:
|
|
lines.append(line)
|
|
if lines:
|
|
yield ''.join(lines)
|
|
|
|
def entries2set(in_file):
|
|
return set(normalize_whitespace(e) for e in iter_entries(in_file))
|
|
|
|
def expected_entries(path):
|
|
path = pathlib.Path(path)
|
|
if not path.is_absolute():
|
|
path = DATA_DIR / path
|
|
with path.open() as in_file:
|
|
return entries2set(in_file)
|
|
|
|
def test_fees_import():
|
|
arglist = ARGLIST + [
|
|
'-c', 'One',
|
|
pathlib.Path(DATA_DIR, 'PatreonEarnings.csv').as_posix(),
|
|
]
|
|
exitcode, stdout, _ = run_main(arglist)
|
|
print(_.getvalue())
|
|
assert exitcode == 0
|
|
actual = entries2set(stdout)
|
|
assert actual == expected_entries('test_main_fees_import.ledger')
|