Files @ 21f6d078a285
Branch filter:

Location: NPO-Accounting/import2ledger/tests/test_outfile.py

Brett Smith
outfile: New module to take over functionality from config.

With the concept of the general "output path" going away, it doesn't make
sense for Config to have an open_output_file method.
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