-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(main): implement adding new materials via MaterialDatabase
- Loading branch information
Showing
4 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
"""Module with filesystem utility functions.""" | ||
|
||
from pathlib import Path | ||
|
||
|
||
def in_directory(file: Path, directory: Path) -> bool: | ||
""" | ||
Determine if a file is located in the supplied directory | ||
or one of its subdirectories. | ||
Args: | ||
file (Path): Path to a file. | ||
directory (Path): Path to a directory. | ||
Returns: | ||
bool: Present in a directory or subdirectories (True) or not (False). | ||
""" | ||
return str(directory.resolve()) in str( | ||
file.resolve() | ||
) and not file.samefile(directory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Module with tests for filesystem utils.""" | ||
|
||
from pathlib import Path | ||
import pytest | ||
|
||
from knowledge_verificator.utils.filesystem import in_directory | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'directory, file, exists_there', | ||
( | ||
('knowledge_verificator', 'knowledge_verificator/main.py', True), | ||
('knowledge_verificator', 'tests/test_filesystem_utils.py', False), | ||
( | ||
'knowledge_verificator', | ||
'knowledge_verificator/utils/filesystem.py', | ||
True, | ||
), | ||
('knowledge_verificator', 'knowledge_verificator', False), | ||
), | ||
) | ||
def test_in_directory(file: str, directory: str, exists_there: bool): | ||
""" | ||
Test if a function determining if a file is located inside a directory | ||
or one of its subdirectories works properly. | ||
""" | ||
assert ( | ||
in_directory(file=Path(file), directory=Path(directory)) == exists_there | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters