diff --git a/tests/test_outfile.py b/tests/test_outfile.py new file mode 100644 index 0000000000000000000000000000000000000000..37f5c9722c9a1a6134d1b3ba2c89c10abead6bf4 --- /dev/null +++ b/tests/test_outfile.py @@ -0,0 +1,23 @@ +import pathlib +import tempfile + +import pytest + +from import2ledger import outfile + +@pytest.mark.parametrize('to_path', [ + lambda s: s, + pathlib.Path, +]) +def test_output_path(to_path): + with tempfile.NamedTemporaryFile() as source_file: + path_arg = to_path(source_file.name) + with outfile.open(path_arg, None) as actual: + assert actual.name == source_file.name + assert 'a' in actual.mode + +def test_fallback(): + with tempfile.NamedTemporaryFile() as source_file: + with outfile.open('-', source_file) as actual: + assert actual is source_file + assert not source_file.closed