Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
664 additions
and
89 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,46 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
_TEMP_FOLDER = 'tmp' | ||
_MODE_EXECUTABLE = 0o755 | ||
_MODE_NON_EXECUTABLE = 0o644 | ||
|
||
|
||
@pytest.fixture() | ||
def make_file(tmp_path): | ||
"""Fixture to make a temporary executable or non executable file.""" | ||
def factory( | ||
filename: str, | ||
file_content: str, | ||
*, | ||
is_executable: bool = False, | ||
) -> str: | ||
temp_folder = tmp_path / _TEMP_FOLDER | ||
temp_folder.mkdir(exist_ok=True) | ||
test_file = temp_folder / filename | ||
file_mode = _MODE_EXECUTABLE if is_executable else _MODE_NON_EXECUTABLE | ||
|
||
test_file.write_text(file_content) | ||
os.chmod(test_file.as_posix(), file_mode) | ||
|
||
return test_file.as_posix() | ||
return factory | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def read_file(absolute_path): | ||
"""Fixture to get the file contents.""" | ||
def factory(filename: str) -> str: | ||
with open(filename) as file_obj: | ||
return file_obj.read() | ||
return factory | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def absolute_path(): | ||
"""Fixture to create full path relative to `contest.py` inside tests.""" | ||
def factory(*files: str): | ||
dirname = os.path.dirname(os.path.dirname(__file__)) | ||
return os.path.join(dirname, *files) | ||
return factory |
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
Oops, something went wrong.