1import os
2from tempfile import NamedTemporaryFile
3import unittest
4from bangaranga import does_the_banga_rang, TheBangaDoesNotRangError
5
6
7class TestStringMethods(unittest.TestCase):
8
9 def create_temp_file(self, content):
10 temp = NamedTemporaryFile( mode="w", delete=False, encoding="utf-8" )
11 temp.write(content)
12 temp.close()
13 self.addCleanup(lambda: os.remove(temp.name))
14 return temp.name
15
16 def test_1(self):
17 f = self.create_temp_file("bangaranga123")
18 self.assertEqual(does_the_banga_rang(f),0)
19
20 def test_2(self):
21 f = self.create_temp_file("bang ga a a rang a ranga")
22 self.assertEqual(does_the_banga_rang(f),3)
23
24 def test_3(self):
25 f = self.create_temp_file("xbangaranga ga ve ran banga")
26 self.assertEqual(does_the_banga_rang(f),0)
27
28 def test_4(self):
29 f = self.create_temp_file("a bang arth ranga")
30 self.assertEqual(does_the_banga_rang(f),0)
31
32 def test_5(self):
33 f = self.create_temp_file("B a a a A NG NG a RA nga")
34 self.assertEqual(does_the_banga_rang(f),6)
35
36 def test_6(self):
37 f = self.create_temp_file("BaNGaRangA")
38 self.assertEqual(does_the_banga_rang(f),1)
39
40 def test_7(self):
41 f = self.create_temp_file("bang ban ran ga ba nga aran r anga")
42 self.assertEqual(does_the_banga_rang(f),4)
43
44 def test_8(self):
45 f = self.create_temp_file("banga ranga ban garanga ba ngaranga ba n garanga bangaranga")
46 self.assertEqual(does_the_banga_rang(f),1)
47
48 def test_9(self):
49 with self.assertRaise(TheBangaDoesNotRangError):
50 does_the_banga_rang(":дръж <ми <>бангарангата")
51
52 def test_10(self):
53 f = self.create_temp_file("bangaranga")
54 self.assertEqual(does_the_banga_rang(f),1)
55
56 def test_11(self):
57 f = self.create_temp_file("banxx garanga")
58 self.assertEqual(does_the_banga_rang(f),0)
59
60 def test_12(self):
61 f = self.create_temp_file("?ban??ga?ranga")
62 self.assertEqual(does_the_banga_rang(f),3)
63
64
65if __name__ == '__main__':
66 unittest.main()
.....F...F
======================================================================
FAIL: test_student_tests_catch_bad_implementation_raises_original_os_error (test.StudentTestSuiteEvaluationTests.test_student_tests_catch_bad_implementation_raises_original_os_error)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 98, in test
self.assertTrue(
~~~~~~~~~~~~~~~^
bad_result["failed_test_ids"],
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
f"Student tests passed against incorrect implementation: {implementation_name!r}.\n{format_student_output(bad_result['output'])}",
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
AssertionError: set() is not true : Student tests passed against incorrect implementation: 'bad_implementation_raises_original_os_error'.
| Output:
| ----------------------------------------------------------------------
| Ran 11 tests in 0.002s
|
| OK
======================================================================
FAIL: test_student_tests_pass_against_correct_implementation (test.StudentTestSuiteEvaluationTests.test_student_tests_pass_against_correct_implementation)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 83, in test_student_tests_pass_against_correct_implementation
self.assertTrue(
~~~~~~~~~~~~~~~^
result["was_successful"], f"Student tests should pass against the correct implementation.\n{student_output}"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
AssertionError: False is not true : Student tests should pass against the correct implementation.
| Output:
| ======================================================================
| ERROR: test_9 (solution.TestStringMethods.test_9)
| ----------------------------------------------------------------------
| Traceback (most recent call last):
| File "/tmp/solution.py", line 49, in test_9
| with self.assertRaise(TheBangaDoesNotRangError):
| ^^^^^^^^^^^^^^^^
| AttributeError: 'TestStringMethods' object has no attribute 'assertRaise'. Did you mean: 'assertRaises'?
|
| ----------------------------------------------------------------------
| Ran 12 tests in 0.003s
|
| FAILED (errors=1)
----------------------------------------------------------------------
Ran 10 tests in 0.088s
FAILED (failures=2)
31.05.2026 18:09
31.05.2026 18:10