Skip to content

Commit f716598

Browse files
committed
changes lisa 2025 plovdiv
1 parent 60b504f commit f716598

File tree

5 files changed

+161
-2
lines changed

5 files changed

+161
-2
lines changed

continuous_integration.pdf

-720 KB
Binary file not shown.

continuous_integration.pptx

1.83 KB
Binary file not shown.

testing_part2.pptx

5.72 MB
Binary file not shown.
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# conftest.py
2+
import pytest
3+
import random
4+
5+
import numpy as np
6+
import pytest
7+
8+
9+
# add a commandline option to pytest
10+
def pytest_addoption(parser):
11+
"""Add random seed option to py.test.
12+
"""
13+
parser.addoption('--seed', dest='seed', type=int, action='store',
14+
help='set random seed')
15+
16+
17+
# configure pytest to automatically set the rnd seed if not passed on CLI
18+
def pytest_configure(config):
19+
seed = config.getvalue("seed")
20+
# if seed was not set by the user, we set one now
21+
if seed is None or seed == ('NO', 'DEFAULT'):
22+
config.option.seed = int(np.random.randint(2 ** 31 - 1))
23+
24+
25+
def pytest_report_header(config):
26+
return f'Using random seed: {config.option.seed}'
27+
28+
29+
@pytest.fixture
30+
def random_state(request):
31+
random_state = np.random.RandomState(request.config.option.seed)
32+
return random_state
33+
34+
35+
# conftest.py
36+
import pytest
37+
import random
38+
39+
FLASHY_EMOJIS_PASS = ["🎉", "✨", "🌈", "💎", "🔥", "🚀", "💃", "🍾", "🥳"]
40+
FLASHY_EMOJIS_FAIL = ["💀", "🔥", "💔", "😱", "👹", "🩸", "☠️", "👾", "🤯"]
41+
FLASHY_EMOJIS_SKIP = ["⏭", "🙃", "🕊", "💤", "📭", "🤸"]
42+
43+
# Vivid ANSI 256-color palette (high contrast, no pale shades)
44+
VIVID_COLORS = [196, 202, 208, 34, 27, 93, 129, 201]
45+
# bright red, orange, gold, green, deep blue, violet, magenta, pink
46+
47+
def rainbow_text(text: str) -> str:
48+
"""Return text with vivid rainbow cycling ANSI 256-color codes."""
49+
result = []
50+
for i, char in enumerate(text):
51+
color = VIVID_COLORS[i % len(VIVID_COLORS)]
52+
result.append(f"\033[38;5;{color}m{char}\033[0m")
53+
return "".join(result)
54+
55+
def big_banner(text: str) -> str:
56+
"""ASCII art style banner with rainbow colors."""
57+
border = rainbow_text("=" * (len(text) + 12))
58+
middle = rainbow_text(f"🌟✨ {text} ✨🌟")
59+
return f"\n{border}\n{middle}\n{border}\n"
60+
61+
def pytest_report_teststatus(report, config):
62+
if report.when == "call":
63+
if report.failed:
64+
return report.outcome, "💥", "FAILED FLASHY"
65+
elif report.passed:
66+
return report.outcome, "🌟", "PASSED FLASHY"
67+
elif report.skipped:
68+
return report.outcome, "⏭", "SKIPPED FLASHY"
69+
70+
@pytest.hookimpl(trylast=True)
71+
def pytest_terminal_summary(terminalreporter, exitstatus, config):
72+
total = terminalreporter._numcollected
73+
failed = len(terminalreporter.stats.get("failed", []))
74+
passed = len(terminalreporter.stats.get("passed", []))
75+
skipped = len(terminalreporter.stats.get("skipped", []))
76+
77+
# Rainbow banner
78+
print(big_banner("PYTEST PARTY REPORT"))
79+
80+
if passed:
81+
emoji = random.choice(FLASHY_EMOJIS_PASS)
82+
print(rainbow_text(f"{emoji} {passed} TESTS PASSED {emoji}"))
83+
if failed:
84+
emoji = random.choice(FLASHY_EMOJIS_FAIL)
85+
print(rainbow_text(f"{emoji} {failed} TESTS FAILED {emoji}"))
86+
if skipped:
87+
emoji = random.choice(FLASHY_EMOJIS_SKIP)
88+
print(rainbow_text(f"{emoji} {skipped} TESTS SKIPPED {emoji}"))
89+
90+
print(big_banner(f"TOTAL: {total}"))
91+
print(rainbow_text("🎆🎇✨ PYTEST PARTY OVER ✨🎇🎆"))
92+
93+
94+
95+
# # Only include colors supported by TerminalWriter.markup
96+
# FLASHY_COLORS = ["red", "green", "yellow", "blue", "cyan", "white"]
97+
98+
# FLASHY_EMOJIS_PASS = ["🎉", "✨", "🌈", "💎", "🔥", "🚀", "💃"]
99+
# FLASHY_EMOJIS_FAIL = ["💀", "🔥", "💔", "😱", "👹", "🩸", "☠️"]
100+
# FLASHY_EMOJIS_SKIP = ["⏭", "🙃", "🕊", "💤", "📭"]
101+
102+
103+
104+
105+
# def random_style(tw, text: str, emojis: list) -> str:
106+
# """Return text wrapped in random color and emoji bling."""
107+
# color = random.choice(FLASHY_COLORS)
108+
# emoji = random.choice(emojis)
109+
# kwargs = {"bold": True, color: True}
110+
# return tw.markup(f"{emoji} {text} {emoji}", **kwargs)
111+
112+
113+
# def pytest_report_teststatus(report, config):
114+
# """Customize symbols in the progress line (dots → flashy)."""
115+
# if report.when == "call":
116+
# if report.failed:
117+
# return report.outcome, "💥", "FAILED FLASHY"
118+
# elif report.passed:
119+
# return report.outcome, "🌟", "PASSED FLASHY"
120+
# elif report.skipped:
121+
# return report.outcome, "⏭", "SKIPPED FLASHY"
122+
123+
124+
# @pytest.hookimpl(trylast=True)
125+
# def pytest_terminal_summary(terminalreporter, exitstatus, config):
126+
# tw = terminalreporter._tw
127+
# total = terminalreporter._numcollected
128+
129+
# failed = len(terminalreporter.stats.get("failed", []))
130+
# passed = len(terminalreporter.stats.get("passed", []))
131+
# skipped = len(terminalreporter.stats.get("skipped", []))
132+
133+
# tw.sep("=", random_style(tw, "🌟🌟 TEST SUMMARY 🌟🌟", FLASHY_EMOJIS_PASS))
134+
135+
# if passed:
136+
# tw.write(random_style(tw, f"{passed} TESTS PASSED", FLASHY_EMOJIS_PASS) + "\n")
137+
# if failed:
138+
# tw.write(random_style(tw, f"{failed} TESTS FAILED", FLASHY_EMOJIS_FAIL) + "\n")
139+
# if skipped:
140+
# tw.write(random_style(tw, f"{skipped} TESTS SKIPPED", FLASHY_EMOJIS_SKIP) + "\n")
141+
142+
# tw.sep("=", random_style(tw, f"TOTAL: {total}", FLASHY_EMOJIS_PASS))
143+
# tw.write("\n")
144+
# tw.write(random_style(tw, "✨ PYTEST PARTY OVER ✨", FLASHY_EMOJIS_PASS) + "\n")

testing_project/test_logistic.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from logistic import f
44

5-
# Add here your test for the logistic map
6-
75

86
def test_f_corner_cases():
97
# Test cases are (x, r, expected)
@@ -14,3 +12,20 @@ def test_f_corner_cases():
1412
for x, r, expected in cases:
1513
result = f(x, r)
1614
assert_allclose(result, expected)
15+
16+
# Hands on 1
17+
#Add a new test for these generic cases using the for-loop pattern:
18+
# x=0.1, r=2.2 => f(x, r)=0.198
19+
# x=0.2, r=3.4 => f(x, r)=0.544
20+
# x=0.5, r=2 => f(x, r)=0.5
21+
22+
23+
# Hands on 2:
24+
# parametrize the above test using @pytest.mark.parametrize
25+
26+
27+
# Hands on 3
28+
# Implement a function iterate_f that runs f for it iterations. Write tests for the following cases:
29+
# x=0.1, r=2.2, it=1 => iterate_f(it, x, r)=[0.1, 0.198]
30+
# x=0.2, r=3.4, it=4 => iterate_f(it, x, r)=[0.2, 0.544, 0.843418, 0.449019, 0.841163]
31+
# x=0.5, r=2, it=3 => iterate_f(it, x, r)=[0.5, 0.5, 0.5, 0.5]

0 commit comments

Comments
 (0)