-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added first unit test for pyprojen #1
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
560f222
Update author name and email address in pyproject.toml file
avr2002 f563f27
removed example fixtures
avr2002 f920c24
replaced logging.warn[deprecated] with logging.warning in src/pyproje…
avr2002 e3a9028
fix: added local import `JsonFile` from pyprojen.json_file in `synth_…
avr2002 ffaa91f
added test_project fixture to setup a temporary project setup for tes…
avr2002 0bd872c
linting changes
avr2002 4729ec4
changed execute-tests workflow last step name to 'Run tests'
avr2002 a0d2418
Updated Python version 3.8 to 3.10 in CI
avr2002 5404a5d
using single quotes in python 3.10 version number in CI file and upda…
avr2002 797e1de
completed tests for text file generation
avr2002 ce9a52c
minor version bump to v0.0.4
avr2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import shutil | ||
import tempfile | ||
from typing import ( | ||
Any, | ||
Generator, | ||
) | ||
|
||
import pytest | ||
|
||
from pyprojen.project import Project | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def test_project() -> Generator[Project, Any, None]: | ||
"""Create a temporary project for testing.""" | ||
# Setup: Create a TestProject instance with a temporary directory | ||
outdir = tempfile.mkdtemp() | ||
project = Project(name="test-project", outdir=outdir) | ||
|
||
# Yield the project for use in the test | ||
yield project | ||
|
||
# Teardown: Cleanup the temporary directory after the test | ||
shutil.rmtree(outdir) |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from pyprojen.project import Project | ||
from pyprojen.textfile import TextFile | ||
from pyprojen.util.synth import synth_snapshot | ||
|
||
TEST_FILE_PATH = "hello/foo.txt" | ||
|
||
|
||
def test__empty_file(test_project: Project): | ||
"""Test that an empty file is created.""" | ||
# GIVEN: The project is already set up by the fixture | ||
|
||
# WHEN: A TextFile is added to the project | ||
TextFile(scope=test_project, file_path=TEST_FILE_PATH) | ||
|
||
# THEN: Take a snapshot of the project and check the file content | ||
output: dict = synth_snapshot(test_project) | ||
|
||
assert output[TEST_FILE_PATH] == "" | ||
|
||
|
||
def test__add_lines(test_project: Project): | ||
"""Test that lines are added to the file.""" | ||
# GIVEN: The project is already set up by the fixture | ||
|
||
# WHEN: A TextFile is added to the project with some lines | ||
TextFile(scope=test_project, file_path=TEST_FILE_PATH, lines=["line 1", "line 2", "line 3"]) | ||
|
||
# THEN: Take a snapshot of the project and check the file content | ||
output: dict = synth_snapshot(test_project) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
assert output[TEST_FILE_PATH] == "\n".join(["line 1", "line 2", "line 3"]) | ||
|
||
|
||
def test__add_lines_and_append(test_project: Project): | ||
"""Test that lines are added to the file and appended.""" | ||
# GIVEN: The project is already set up by the fixture | ||
|
||
# WHEN: A TextFile is added to the project with some lines | ||
tf = TextFile(scope=test_project, file_path=TEST_FILE_PATH, lines=["line 1", "line 2"]) | ||
|
||
# AND: More lines are appended | ||
tf.add_line("line 3") | ||
tf.add_line("line 4") | ||
|
||
# THEN: Take a snapshot of the project and check the file content | ||
output: dict = synth_snapshot(test_project) | ||
|
||
assert output[TEST_FILE_PATH] == "\n".join(["line 1", "line 2", "line 3", "line 4"]) |
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 |
---|---|---|
@@ -1 +1 @@ | ||
v0.0.3 | ||
v0.0.4 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Genius. So cool that this works.