initial commit

This commit is contained in:
Timo Zimmermann 2024-01-27 18:13:22 +00:00
commit 95af304eb3
13 changed files with 306 additions and 0 deletions

0
app/__init__.py Normal file
View file

30
app/code.py Normal file
View file

@ -0,0 +1,30 @@
# coding: utf-8
import logging
from waffle import switch_is_active
logger = logging.getLogger("app_tests")
def simple(name: str) -> str:
name = name.replace(" ", "-")
name = name.lower()
return name
def complex_function(x: int, y: int) -> int:
if switch_is_active("new_complex"):
return rewrite_complex_function(x, y)
return deprecated_complex_function(x, y)
def rewrite_complex_function(x: int, y: int) -> int:
logger.info("rewrite complex")
return x * y
def deprecated_complex_function(x: int, y: int) -> int:
logger.info("deprecated complex")
return x * y

25
app/tests.py Normal file
View file

@ -0,0 +1,25 @@
# coding: utf-8
import pytest
from waffle.testutils import override_switch
from app.code import simple, complex_function
@pytest.mark.parametrize(
"name",
(
"foo bar",
"baz zab",
"1 2 3 4 5"
)
)
def test_simple(name):
assert " " not in simple(name)
@pytest.mark.parametrize("switch", (True, False))
@pytest.mark.django_db
def test_complex_function(switch):
with override_switch("new_complex", active=switch):
assert complex_function(2, 2) == 4