build: renamed directory from test_tutorial to tests_tutorial for pytest
This commit is contained in:
1 parent
c577565301
commit
69ac65795a
4 files changed
No files matched your search
@@ -0,0 +1,21 @@
|
||||
from src.tutorial.testing.shop.pricing import discount_price
|
||||
import pytest
|
||||
|
||||
|
||||
def test_discount_price_reduces_price():
|
||||
result = discount_price(100.0, 20.0)
|
||||
assert result == 80
|
||||
|
||||
assert discount_price(100.0, 50.0) == 50
|
||||
assert discount_price(100.0, 0) == 100
|
||||
assert discount_price(100.0, 100) == 0
|
||||
|
||||
|
||||
def test_negative_orice_raises_value_error() -> None:
|
||||
with pytest.raises(ValueError):
|
||||
discount_price(-100.0, 50.0) is ValueError
|
||||
|
||||
|
||||
def test_percent_above_hundered_message() -> None:
|
||||
with pytest.raises(ValueError, match="between 0 and 100"):
|
||||
discount_price(100.0, 150.0)
|
||||
@@ -0,0 +1,24 @@
|
||||
from src.tutorial.testing.practice.catching_exeptions import double_integers
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("input", "expected"),
|
||||
[
|
||||
([1, 2, 3], [2, 4, 6]),
|
||||
([5], [10]),
|
||||
([100, 900, -2], [200, 1800, -4]),
|
||||
],
|
||||
)
|
||||
def test_double_integers(input, expected):
|
||||
assert double_integers(input) == expected
|
||||
|
||||
|
||||
def test_argument_is_list():
|
||||
with pytest.raises(TypeError, match="data must be a list"):
|
||||
double_integers(4)
|
||||
|
||||
|
||||
def test_list_with_integers_only():
|
||||
with pytest.raises(TypeError, match="data may contain only integers"):
|
||||
double_integers([4, 3, 2, "str"])
|
||||
@@ -0,0 +1,24 @@
|
||||
from src.tutorial.testing.practice.kata_list_filtering import filter_list
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("input", "expected"),
|
||||
[
|
||||
([3, 5, "m", "0", 7], [3, 5, 7]),
|
||||
(["3", "5", "m", "0", "f"], []),
|
||||
([1, 2, 3], [1, 2, 3]),
|
||||
],
|
||||
)
|
||||
def test_filter_list(input, expected):
|
||||
assert filter_list(input) == expected
|
||||
|
||||
|
||||
def test_parameter_is_list():
|
||||
input = [7, 9, 0]
|
||||
result = isinstance(input, list)
|
||||
assert result
|
||||
|
||||
input = 9
|
||||
result = isinstance(input, list)
|
||||
assert not result
|
||||
@@ -0,0 +1,20 @@
|
||||
from src.tutorial.testing.practice.pandas_filter_rows import filter_dataframe
|
||||
import pytest
|
||||
import pandas as pd
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def standard_df():
|
||||
df = pd.DataFrame(
|
||||
{
|
||||
"A": [1, 2, 3, 4, 5],
|
||||
"B": [0, 2, 2, 4, 5],
|
||||
"C": [1, 2, 3, 8, 5],
|
||||
}
|
||||
)
|
||||
return df
|
||||
|
||||
|
||||
def test_col_not_in_dataframe(standard_df):
|
||||
with pytest.raises(ValueError):
|
||||
filter_dataframe(standard_df, "Z", lambda x: x >= 4)
|
||||
Reference in new issue
Block a user