1import io
2import sys
3import unittest
4
5
6class StdBuffer:
7 def __init__(self):
8 self.buffer = io.StringIO()
9
10 def __enter__(self):
11 self.stds = sys.stdin, sys.stderr, sys.stdout
12 sys.stdin = self.buffer
13 sys.stderr = self.buffer
14 sys.stdout = self.buffer
15
16 def __exit__(self, *args, **kwargs):
17 sys.stdin, sys.stderr, sys.stdout = self.stds
18
19
20with StdBuffer():
21 import solution
22
23
24class TestLuck(unittest.TestCase):
25
26 def test_luck(self):
27 self.assertIn('Х', dir(solution), 'Убеди се, че имаш променлива "Х"')
28
29
30if __name__ == "__main__":
31 unittest.main()
1import unittest
2
3from solution import Х
4from info import POSITION
5
6
7class TestLuck(unittest.TestCase):
8
9 def test_luck(self):
10 self.assertEqual(Х, POSITION)
11
12
13if __name__ == '__main__':
14 unittest.main()
|
|
Георги Кунчев
21.11.2024 15:19Като изключение, понеже няма скрито-покрито, качвам теста отсега.
```
import unittest
from solution import Х
from info import POSITION # Поредният ви номер влиза магически
class TestLuck(unittest.TestCase):
def test_luck(self):
self.assertEqual(Х, POSITION)
if __name__ == '__main__':
unittest.main()
```
|