-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests_test_clock.py
49 lines (41 loc) · 1.39 KB
/
tests_test_clock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pytest
from datetime import datetime
import pytz
from sonw.time.clock import WorldClock
import tkinter as tk
import threading
import time
@pytest.fixture
def clock():
clock = WorldClock(['UTC', 'US/Pacific'])
yield clock
clock.stop()
def test_clock_initialization(clock):
assert len(clock.timezones) == 2
assert 'UTC' in clock.timezones
assert 'US/Pacific' in clock.timezones
assert isinstance(clock.root, tk.Tk)
assert clock.running
assert isinstance(clock.update_thread, threading.Thread)
def test_timezone_addition(clock):
clock.add_timezone('Europe/London')
assert 'Europe/London' in clock.timezones
assert 'Europe/London' in clock.time_labels
def test_timezone_removal(clock):
clock.remove_timezone('US/Pacific')
assert 'US/Pacific' not in clock.timezones
assert 'US/Pacific' not in clock.time_labels
def test_time_update(clock):
# Let the clock update a few times
time.sleep(0.3)
for zone in clock.timezones:
label_text = clock.time_labels[zone].cget("text")
assert len(label_text) == 8 # HH:MM:SS format
# Verify time format
try:
datetime.strptime(label_text, "%H:%M:%S")
except ValueError:
pytest.fail(f"Invalid time format for {zone}: {label_text}")
def test_invalid_timezone():
with pytest.raises(Exception):
WorldClock(['InvalidZone'])