File diff f3c3ebcf59e2 → 3721226d17fe
tests/test_books_loader.py
Show inline comments
...
 
@@ -225,3 +225,52 @@ def test_load_none_no_args():
 
    assert errors
 
    assert all(isinstance(err.source['filename'], str) for err in errors)
 
    assert all(isinstance(err.source['lineno'], int) for err in errors)
 

	
 
def test_dispatch_empty():
 
    result = books.Loader.dispatch(None)
 
    assert not result.entries
 
    assert result.errors
 

	
 
@pytest.mark.parametrize('from_arg', [
 
    None,
 
    *range(2018, 2021),
 
    date(2019, 2, 1),
 
    date(2019, 9, 15),
 
    date(2020, 1, 20),
 
    date(2020, 5, 31),
 
])
 
def test_dispatch_load_all_from_year(conservancy_loader, from_arg):
 
    try:
 
        from_year = from_arg.year
 
    except AttributeError:
 
        from_year = from_arg or 2018
 
    else:
 
        if from_arg.month < FY_START_MONTH:
 
            from_year -= 1
 
    result = books.Loader.dispatch(conservancy_loader, from_arg)
 
    check_openings(result.entries)
 
    actual_years = txn_years(result.entries)
 
    assert actual_years.issuperset(range(from_year, 2021))
 
    assert min(actual_years) == from_year
 
    assert not result.errors
 

	
 
@pytest.mark.parametrize('from_arg,to_arg,expected', [
 
    (2019, 2019, range(2019, 2020)),
 
    (0, 2019, range(2019, 2020)),
 
    (2018, 2019, range(2018, 2020)),
 
    (1, 2018, range(2018, 2020)),
 
    (-1, 2019, range(2018, 2020)),
 
    (2019, 2020, range(2019, 2021)),
 
    (1, 2019, range(2019, 2021)),
 
    (-1, 2020, range(2019, 2021)),
 
    (2010, 2030, range(2018, 2021)),
 
    (20, 2010, range(2018, 2021)),
 
    (-20, 2030, range(2018, 2021)),
 
])
 
def test_dispatch_load_all_fy_range(conservancy_loader, from_arg, to_arg, expected):
 
    result = books.Loader.dispatch(conservancy_loader, from_arg, to_arg)
 
    check_openings(result.entries)
 
    actual_years = txn_years(result.entries)
 
    assert actual_years.issuperset(iter(expected))
 
    assert min(actual_years) == expected.start
 
    assert not result.errors