|
1 | 1 | from codonpython.file_utils import compare |
2 | 2 | from codonpython.file_utils import file_search |
3 | 3 | from codonpython.file_utils import import_files |
| 4 | +from tests.utils import DfWrap |
4 | 5 | import numpy as np |
5 | 6 | import pytest |
6 | 7 | import pandas as pd |
7 | 8 |
|
| 9 | + |
| 10 | + |
8 | 11 | df1 = pd.DataFrame( |
9 | 12 | { |
10 | 13 | "A": [1, 5, 6, 1, 8, 5, 9], |
@@ -97,20 +100,36 @@ def test_compare_BAU(x, y, names, dups, same, expected): |
97 | 100 | def test_file_search_BAU(doctype, like, strict, expected): |
98 | 101 | assert file_search(doctype=doctype, like=like, strict=strict) == expected |
99 | 102 |
|
100 | | -file_import_path = './tests' |
| 103 | +df_test_import = pd.DataFrame({ |
| 104 | + "test": ["test"] |
| 105 | +}) |
| 106 | +df_test_import = DfWrap(df_test_import) |
101 | 107 |
|
102 | | -@pytest.mark.parametrize("expected", [({})]) |
103 | | -def test_import_files_BAU(expected): |
104 | | - assert import_files(file_import_path) == expected |
| 108 | +expected_imports_subdir_search = { |
| 109 | + '/tests/import_files/test': df_test_import, |
| 110 | + '/tests/import_files/subdir/subdir_test': df_test_import |
| 111 | +} |
| 112 | +expected_imports_no_subdirs = {'test': df_test_import} |
| 113 | +expected_imports_filename_match = {'/tests/import_files/subdir/subdir_test': df_test_import} |
105 | 114 |
|
106 | | -@pytest.mark.parametrize("subdir, expected", [(True, {})]) |
107 | | -def test_import_files_BAU_2(subdir, expected): |
| 115 | +@pytest.mark.parametrize("file_import_path, subdir, expected", [('./tests', False, {})]) |
| 116 | +def test_import_files_when_none_found(file_import_path, subdir, expected): |
108 | 117 | assert import_files(file_import_path, subdir=subdir) == expected |
109 | 118 |
|
110 | | - |
111 | | -@pytest.mark.parametrize("strict,subdir, expected", [(True, True, {})]) |
112 | | -def test_import_files_BAU_3(strict, subdir, expected): |
113 | | - assert import_files(file_import_path, strict=strict, subdir=subdir) == expected |
| 119 | +@pytest.mark.parametrize("file_import_path, subdir, strict, like, expected", [ |
| 120 | + ('./tests/import_files', False, False, [''], expected_imports_no_subdirs), |
| 121 | + ('./tests/import_files', True, False, [''], expected_imports_subdir_search), |
| 122 | + ('./tests/import_files', True, True, ['subdir'], expected_imports_filename_match), |
| 123 | +]) |
| 124 | +def test_import_files_csv(file_import_path, subdir, strict, like, expected): |
| 125 | + imported_files = import_files(file_import_path, subdir=subdir, strict=strict, like=like) |
| 126 | + |
| 127 | + # in the default csv mode, import_files() returns a dict with a pandas df for every csv file it finds. |
| 128 | + # The loop below wraps each dfs in the DfWrap class, so that the dicts can be compared with |
| 129 | + # the expected results for equality. |
| 130 | + for file in imported_files: |
| 131 | + imported_files[file] = DfWrap(imported_files[file]) |
| 132 | + assert imported_files == expected |
114 | 133 |
|
115 | 134 |
|
116 | 135 | # ----------------Console output------------------------- |
|
0 commit comments