Skip to content

Commit

Permalink
Fixed test_utils after rebasing
Browse files Browse the repository at this point in the history
  • Loading branch information
JosePizarro3 committed Dec 18, 2024
1 parent 415074d commit 3daf71b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@
"justMyCode": false,
"args": ["export-entities-to-json"]
},
{
"name": "bds export-to-excel",
"type": "debugpy",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/.venv/bin/bam_data_store",
"justMyCode": false,
"args": ["export-entities-to-excel"]
},
]
},
}
31 changes: 14 additions & 17 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
)


@pytest.fixture(autouse=True)
def clear_log_storage():
"""Fixture to clear the log storage before each test."""
log_storage.clear()


@pytest.mark.parametrize(
'directory_path, dir_exists',
[
Expand All @@ -27,16 +21,18 @@ def clear_log_storage():
('tests/data/tmp/', True),
],
)
def test_delete_and_create_dir(directory_path: str, dir_exists: bool):
def test_delete_and_create_dir(
cleared_log_storage: list, directory_path: str, dir_exists: bool
):
"""Tests the `delete_and_delete_dir` function."""
delete_and_create_dir(directory_path=directory_path, logger=logger)
assert dir_exists == os.path.exists(directory_path)
if dir_exists:
shutil.rmtree(directory_path) # ! careful with this line
else:
assert len(log_storage) == 1
assert log_storage[0]['level'] == 'warning'
assert 'directory_path' in log_storage[0]['event']
assert len(cleared_log_storage) == 1
assert cleared_log_storage[0]['level'] == 'warning'
assert 'directory_path' in cleared_log_storage[0]['event']


@pytest.mark.parametrize(
Expand All @@ -53,11 +49,8 @@ def test_delete_and_create_dir(directory_path: str, dir_exists: bool):
('./tests/data', [], 'No Python files found in the directory.', 'info'),
# Python files found in the directory
(
'./tests',
'./tests/utils',
[
'./tests/conftest.py',
'./tests/metadata/test_entities.py',
'./tests/metadata/test_definitions.py',
'./tests/utils/test_utils.py',
],
None,
Expand All @@ -66,13 +59,17 @@ def test_delete_and_create_dir(directory_path: str, dir_exists: bool):
],
)
def test_listdir_py_modules(
directory_path: str, listdir: list[str], log_message: str, log_message_level: str
cleared_log_storage: list,
directory_path: str,
listdir: list[str],
log_message: str,
log_message_level: str,
):
"""Tests the `listdir_py_modules` function."""
result = listdir_py_modules(directory_path=directory_path, logger=logger)
if not listdir:
assert log_storage[0]['event'] == log_message
assert log_storage[0]['level'] == log_message_level
assert cleared_log_storage[0]['event'] == log_message
assert cleared_log_storage[0]['level'] == log_message_level
# when testing locally and with Github actions the order of the files is different --> `result` is sorted, so we also sort `listdir`
assert result == sorted(listdir)

Expand Down

1 comment on commit 3daf71b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
bam_data_store
   logger.py80100% 
bam_data_store/cli
   cli.py363636 0%
   entities_to_excel.py404040 0%
   entities_to_json.py353535 0%
bam_data_store/datamodel
   collection_types.py777 0%
   dataset_types.py00100% 
   object_types.py111111 0%
   property_types.py222 0%
   vocabulary_types.py141414 0%
bam_data_store/metadata
   definitions.py7844 95%
   entities.py4533 93%
bam_data_store/utils
   utils.py341111 68%
TOTAL31016347% 

Tests Skipped Failures Errors Time
50 1 💤 0 ❌ 0 🔥 0.279s ⏱️

Please sign in to comment.