-
Notifications
You must be signed in to change notification settings - Fork 3k
Solution #3606
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
Open
z47cg46ky2-beep
wants to merge
4
commits into
mate-academy:master
Choose a base branch
from
z47cg46ky2-beep:develop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Solution #3606
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,3 +1,8 @@ | ||
| import pytest | ||
| import inspect | ||
| import app.main | ||
|
|
||
| # Оголошення змінних | ||
| lucky_number = 777 | ||
| pi = 3.14 | ||
| one_is_a_prime_number = False | ||
|
|
@@ -10,10 +15,115 @@ | |
| "The Matrix", | ||
| ] | ||
| profile_info = ("michel", "michel@gmail.com", "12345678") | ||
| marks = { | ||
| "John": 4, | ||
| "Sergio": 3, | ||
| } | ||
| marks = {"John": 4, "Sergio": 3} | ||
| collection_of_coins = {1, 2, 25} | ||
|
|
||
| # write your code here | ||
| # Формування словника | ||
| sorted_variables = { | ||
| "immutable": [ | ||
| lucky_number, | ||
| pi, | ||
| one_is_a_prime_number, | ||
| name, | ||
| profile_info, | ||
| ], | ||
| "mutable": [ | ||
| my_favourite_films, | ||
| marks, | ||
| collection_of_coins, | ||
| ], | ||
| } | ||
|
|
||
| # Тести | ||
| @pytest.mark.parametrize( | ||
| "variable_name", | ||
| [ | ||
| "lucky_number", | ||
| "pi", | ||
| "one_is_a_prime_number", | ||
| "name", | ||
| "my_favourite_films", | ||
| "profile_info", | ||
| "marks", | ||
| "collection_of_coins", | ||
| "sorted_variables", | ||
| ], | ||
| ) | ||
| def test_variables_should_be_defined(variable_name): | ||
| assert hasattr( | ||
| app.main, variable_name | ||
| ), f"Variable '{variable_name}' should be defined." | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "variable,value", | ||
| [ | ||
| ("lucky_number", 777), | ||
| ("pi", 3.14), | ||
| ("one_is_a_prime_number", False), | ||
| ("name", "Richard"), | ||
| ( | ||
| "my_favourite_films", | ||
| [ | ||
| "The Shawshank Redemption", | ||
| "The Lord of the Rings: The Return of the King", | ||
| "Pulp Fiction", | ||
| "The Good, the Bad and the Ugly", | ||
| "The Matrix", | ||
| ], | ||
| ), | ||
| ("profile_info", ("michel", "michel@gmail.com", "12345678")), | ||
| ("marks", {"John": 4, "Sergio": 3}), | ||
| ("collection_of_coins", {1, 2, 25}), | ||
| ], | ||
| ) | ||
| def test_variables_values(variable, value): | ||
| assert ( | ||
| getattr(app.main, variable) == value | ||
| ), f"Variable '{variable}' should be equal to {value}." | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "variable_name", | ||
| [ | ||
| "lucky_number", | ||
| "pi", | ||
| "one_is_a_prime_number", | ||
| "name", | ||
| "my_favourite_films", | ||
| "profile_info", | ||
| "marks", | ||
| "collection_of_coins", | ||
| ], | ||
| ) | ||
| def test_variables_should_be_added_to_sorted_variables(variable_name): | ||
| sorted_variables = getattr(app.main, "sorted_variables") | ||
| assert ( | ||
| getattr(app.main, variable_name) in sorted_variables["mutable"] or | ||
| getattr(app.main, variable_name) in sorted_variables["immutable"] | ||
| ), f"Variable '{variable_name}' should be added to 'sorted_variables'" | ||
|
|
||
|
|
||
| def is_immutable(obj): | ||
| if isinstance(obj, (int, str, bool, float, tuple)): | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| def test_variables_added_to_the_correct_list(): | ||
| sorted_variables = getattr(app.main, "sorted_variables") | ||
| for variable in sorted_variables["mutable"]: | ||
| assert is_immutable(variable) is False, ( | ||
| f"{variable} should be in 'immutable' list" | ||
| ) | ||
|
|
||
| for variable in sorted_variables["immutable"]: | ||
| assert is_immutable(variable) is True, ( | ||
| f"{variable} should be in 'mutable' list" | ||
| ) | ||
|
|
||
|
|
||
| def test_removed_comment(): | ||
| with open(app.main.__file__, "r") as f: | ||
| lines = inspect.getsource(app.main) | ||
| assert "# write your code here" not in lines | ||
|
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 task only requires defining variables and the |
||
This file contains hidden or 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.
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.
This file should only contain your implementation (variable declarations and
sorted_variables);pytest,inspect, andimport app.mainare test-related and belong in the tests module, not inapp/main.py.