From 1cedf933c8f50e773b51287f4465f2a51f24bc66 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Fri, 4 Dec 2020 23:46:51 -0700 Subject: [PATCH] Fix tests that implicitly depend on libmagic The generic importer source takes a directory, looks at all files in that directory recursively, and then filters down to the files that are of the right type for its importer. The tests for it point it to a directory that contains not only the test source CSV file, but also the test verification beancount and JSON files. I haven't verified, but I'm guessing this worked for the original author because they had `python-magic` and `libmagic` installed. But without those installed, beancount's file-identification fails (ironically) on the `.beancount` files, causing these tests to fail. Since `libmagic` is supposed to be an optional dependency of beancount, and it can't be listed as an automatic test dependency (since it's not a Python library), the tests should not require it in order to pass. This behavior of the generic importer (silently excluding files of a type it doesn't know how to handle) seems a bit too magical and implicit for my tastes, but since I didn't author and don't use this importer I'm not changing its behavior. Instead I just rearranged the test data directory so the source CSV file is in its own subdirectory, eliminating the problem of making the importer identify the various other test support files. With this PR all tests are green again, even without `libmagic` installed. --- .../source/generic_importer_source_test.py | 4 +++- .../generic_importer/{ => csv}/generic_statement.csv | 0 .../test_basic/import_results.beancount | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) rename testdata/source/generic_importer/{ => csv}/generic_statement.csv (100%) diff --git a/beancount_import/source/generic_importer_source_test.py b/beancount_import/source/generic_importer_source_test.py index 087a3543..26607f9f 100644 --- a/beancount_import/source/generic_importer_source_test.py +++ b/beancount_import/source/generic_importer_source_test.py @@ -9,6 +9,8 @@ os.path.join( os.path.dirname(__file__), '..', '..', 'testdata', 'source', 'generic_importer')) +testdata_csv = os.path.join(testdata_dir, "csv") + examples = [ 'test_basic', 'test_invalid', @@ -31,7 +33,7 @@ def test_source(name: str): example_dir=os.path.join(testdata_dir, name), source_spec={ 'module': 'beancount_import.source.generic_importer_source', - 'directory': testdata_dir, + 'directory': testdata_csv, 'account': 'Assets:Bank', 'importer': importer, }, diff --git a/testdata/source/generic_importer/generic_statement.csv b/testdata/source/generic_importer/csv/generic_statement.csv similarity index 100% rename from testdata/source/generic_importer/generic_statement.csv rename to testdata/source/generic_importer/csv/generic_statement.csv diff --git a/testdata/source/generic_importer/test_basic/import_results.beancount b/testdata/source/generic_importer/test_basic/import_results.beancount index 1912e28a..1913b38e 100644 --- a/testdata/source/generic_importer/test_basic/import_results.beancount +++ b/testdata/source/generic_importer/test_basic/import_results.beancount @@ -1,5 +1,5 @@ ;; date: 2020-01-01 -;; info: {"filename": "/generic_statement.csv", "line": 1, "type": "text/csv"} +;; info: {"filename": "/csv/generic_statement.csv", "line": 1, "type": "text/csv"} ; features: [ ; { @@ -18,7 +18,7 @@ Expenses:FIXME 1 USD ;; date: 2020-01-01 -;; info: {"filename": "/generic_statement.csv", "line": 2, "type": "text/csv"} +;; info: {"filename": "/csv/generic_statement.csv", "line": 2, "type": "text/csv"} ; features: [ ; { @@ -37,7 +37,7 @@ Expenses:FIXME 1 USD ;; date: 2020-01-02 -;; info: {"filename": "/generic_statement.csv", "line": 3, "type": "text/csv"} +;; info: {"filename": "/csv/generic_statement.csv", "line": 3, "type": "text/csv"} ; features: [ ; { @@ -56,7 +56,7 @@ Expenses:FIXME -1 USD ;; date: 2020-01-02 -;; info: {"filename": "/generic_statement.csv", "line": 5, "type": "text/csv"} +;; info: {"filename": "/csv/generic_statement.csv", "line": 5, "type": "text/csv"} ; features: [ ; { @@ -75,7 +75,7 @@ Expenses:FIXME -1 USD ;; date: 2020-01-02 -;; info: {"filename": "/generic_statement.csv", "line": 4, "type": "text/csv"} +;; info: {"filename": "/csv/generic_statement.csv", "line": 4, "type": "text/csv"} ; features: [ ; { @@ -94,7 +94,7 @@ Expenses:FIXME -500 USD ;; date: 2020-01-05 -;; info: {"filename": "/generic_statement.csv", "line": 6, "type": "text/csv"} +;; info: {"filename": "/csv/generic_statement.csv", "line": 6, "type": "text/csv"} ; features: [ ; {