Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 115 additions & 5 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import pytest
import inspect
import app.main

Copy link
Copy Markdown

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, and import app.main are test-related and belong in the tests module, not in app/main.py.


# Оголошення змінних
lucky_number = 777
pi = 3.14
one_is_a_prime_number = False
Expand All @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The task only requires defining variables and the sorted_variables dictionary; from here down you have test code that duplicates what already exists in tests/test_main.py and should be removed from the main module.

6 changes: 0 additions & 6 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,3 @@ def test_variables_added_to_the_correct_list():
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
Loading