Добавлены тесты для всех классов

This commit is contained in:
Ilia Miheev
2026-04-30 00:41:27 +03:00
parent 4db335f399
commit d1b1fd8e0b
7 changed files with 511 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
import time
import pytest
from ipars import TimerManager
def test_getWorkTime_seconds():
timer = TimerManager()
timer.start()
time.sleep(0.1)
timer.end()
result = timer.getWorkTime('seconds')
assert 0.05 < result < 0.5
def test_getWorkTime_minutes():
timer = TimerManager()
timer.start()
time.sleep(0.1)
timer.end()
result = timer.getWorkTime('minutes')
assert result < 0.01
def test_getWorkTime_hours():
timer = TimerManager()
timer.start()
time.sleep(0.1)
timer.end()
result = timer.getWorkTime('hours')
assert result < 0.001
def test_getWorkTime_ndigits():
timer = TimerManager()
timer.start()
time.sleep(0.1)
timer.end()
result = timer.getWorkTime('seconds', ndigits=2)
assert isinstance(result, float)
assert len(str(result).split('.')[-1]) <= 2
def test_getWorkTime_returns_float():
timer = TimerManager()
timer.start()
timer.end()
result = timer.getWorkTime()
assert isinstance(result, float)
def test_raises_without_start():
timer = TimerManager()
with pytest.raises(ValueError, match='"start"'):
timer.getWorkTime()
def test_raises_without_end():
timer = TimerManager()
timer.start()
with pytest.raises(ValueError, match='"end"'):
timer.getWorkTime()
def test_raises_invalid_format():
timer = TimerManager()
timer.start()
timer.end()
with pytest.raises(ValueError, match='milliseconds'):
timer.getWorkTime('milliseconds')