beancount / fava

Fava - web interface for Beancount
https://beancount.github.io/fava/
MIT License
1.97k stars 285 forks source link

test_core_ingest.py --> test_ingest_examplefile test is failing on Windows #618

Closed bmjjr closed 6 years ago

bmjjr commented 6 years ago

Hi, thanks for this great project. Briefly, I'm trying to integrate Fava as a flask blueprint into part of a larger app I'm working on. To further complicate things a bit, I'm doing it on Windows.

Now, I've ported beancount to windows and all the beancount tests pass on windows (after a long slog through all of them to fix path comparison issues).

I've also got the tests passing on fava except this one nagging test failure with the test_ingest_examplefile test.

The assert for assert entries[0].comment == 'Hinweis: Zinssatz auf 0,15% geändert' is failing. From what I've read and the source, I understand there is currently poor support for unicode in beancount. We do need as much unicode support as we can get so I was already thinking how to improve it.

So do you currently have this assert passing? I would expect the assert to fail due to the lack of unicode support. Or maybe it is connected to my windows port. But maybe you've made some modification?

Any clarity on this test and the situation would be appreciated.

bmjjr commented 6 years ago

Failure code:

================================== FAILURES ===================================
___________________________ test_ingest_examplefile ___________________________

ingest_ledger = <base.bp.fava.core.FavaLedger object at 0x000002169ED61468>

    def test_ingest_examplefile(ingest_ledger):
        identify_dir = list(ingest_ledger.ingest.identify_directory('.'))
        assert len(identify_dir) == 1

        filename, importers = identify_dir[0]
        importer_name = importers[0].name()
        entries = ingest_ledger.ingest.extract(filename, importer_name)
        assert len(entries) == 4
        assert entries[0].date == datetime.date(2017, 2, 12)
>       assert entries[0].comment == 'Hinweis: Zinssatz auf 0,15% geändert'
E       AssertionError: assert 'Hinweis: Zin...15% geändert' == 'Hinweis: Zins...,15% geändert'
E         - Hinweis: Zinssatz auf 0,15% geändert
E         ?                               ^^
E         + Hinweis: Zinssatz auf 0,15% geändert
E         ?                               ^

test_core_ingest.py:27: AssertionError
========================== 1 failed in 1.14 seconds ===========================
yagebu commented 6 years ago

I guess this is due to some open() being called without a encoding argument. Does adding encoding='utf-8' to the one in tests/data/import.config fix it?

bmjjr commented 6 years ago

Yes, that was it. Thank you!

bmjjr commented 6 years ago

@yagebu Recently updated all my project dependencies and have another test failure on windows in test_core_ingest.py file. At this point, I'm a few merges behind your repo and also beancount master.
The initial failure is on line assert entries[0].date == datetime.date(2017, 2, 12) as shown below.

tests\basetests\bp\fava\test_core_ingest.py:10 (test_ingest_examplefile)
datetime.date(2017, 2, 12) != datetime.date(2017, 2, 14)

Expected :datetime.date(2017, 2, 14)
Actual   :datetime.date(2017, 2, 12)
 <Click to see difference>

def test_ingest_examplefile():
        ingest_ledger = FavaLedger(FILE_PATH)
        identify_dir = list(ingest_ledger.ingest.identify_directory('.'))
        assert len(identify_dir) == 1

        filename, importers = identify_dir[0]
        importer_name = importers[0].name()
        entries = ingest_ledger.ingest.extract(filename, importer_name)
        assert len(entries) == 4
>       assert entries[0].date == datetime.date(2017, 2, 12)
E       AssertionError: assert datetime.date(2017, 2, 14) == datetime.date(2017, 2, 12)
E        +  where datetime.date(2017, 2, 14) = Transaction(meta={'filename': 'C:/Users/bjord/repos/aoscrdb_app/tests/basetests/bp/fava/data/import.csv', 'lineno': 0,...=None, meta=None), Posting(account='Assets:Checking', units=-100.00 EUR, cost=None, price=None, flag=None, meta=None)]).date
E        +  and   datetime.date(2017, 2, 12) = <class 'datetime.date'>(2017, 2, 12)
E        +    where <class 'datetime.date'> = datetime.date

basetests\bp\fava\test_core_ingest.py:20: AssertionError

When I comment out assert entries[0].date == datetime.date(2017, 2, 12) and then I get a failure on the next line assert entries[0].comment == 'Hinweis: Zinssatz auf 0,15% geändert' as shown below:

F
tests\basetests\bp\fava\test_core_ingest.py:10 (test_ingest_examplefile)
def test_ingest_examplefile():
        ingest_ledger = FavaLedger(FILE_PATH)
        identify_dir = list(ingest_ledger.ingest.identify_directory('.'))
        assert len(identify_dir) == 1

        filename, importers = identify_dir[0]
        importer_name = importers[0].name()
        entries = ingest_ledger.ingest.extract(filename, importer_name)
        assert len(entries) == 4
        # assert entries[0].date == datetime.date(2017, 2, 12)
>       assert entries[0].comment == 'Hinweis: Zinssatz auf 0,15% geändert'
E       AttributeError: 'Transaction' object has no attribute 'comment'

test_core_ingest.py:21: AttributeError

Finally, when I comment out both lines, the test passes. So it seems to be an issue with the entries[0] reference items. Wanted to check with you first to see if anything specific pops to mind in recent pull requests that might explain this failure (and before I spend more time diving into the import.config logic). Thanks.

bmjjr commented 6 years ago

When I change both lines to:

assert entries[2].date == datetime.date(2017, 2, 12)
assert entries[2].comment == 'Hinweis: Zinssatz auf 0,15% geändert'

The test passes. For the record, I just updated to python 3.6.4 but otherwise, passing all the beancount and remaining fava tests. My import.config is same as current repo.

bmjjr commented 6 years ago

Changing return entries to return data.sorted(entries) in the import.config resolved the test error.

yagebu commented 6 years ago

This was due to a bug in Beancount, which is fixed now: https://bitbucket.org/blais/beancount/issues/219/extract-does-not-sort-entries-anymore