Skip to content

Commit

Permalink
Add basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jake158 committed Apr 4, 2024
1 parent 33b7da2 commit a6dfb72
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ Pomodoro timer GUI with Discord Rich Presence integration and stats tracking
## Acknowledgements

Some themes adapted from: https://github.com/avalon60/ctk_theme_builder/tree/develop/user_themes

## Testing
`python3 -m unittest discover tests`
4 changes: 4 additions & 0 deletions pomodorodiscord/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## Running

`python3 run.py`

## Structure

Expand All @@ -17,6 +20,7 @@
- `graphs.py`: matplotlib plots using data collected.
- `sounds/`: Beep.
- `themes/`: Responsible for all colors in the GUI. Theme is loaded on launch in run.py.
- `tests/`: Basic tests. Ignore ResourceWarnings.

## File Dependencies

Expand Down
92 changes: 92 additions & 0 deletions pomodorodiscord/tests/test_pom_frame.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import warnings
import unittest
from src.frames.pomodoro_frame import PomodoroFrame
from src.utils import load_config, DEF_POMODORO_MINS, DEF_SB_BEFORE_L


def ignore_warnings(test_func):
def do_test(self, *args, **kwargs):
with warnings.catch_warnings():
warnings.simplefilter("ignore", ResourceWarning)
test_func(self, *args, **kwargs)
return do_test


class TestPomodoroFrame(unittest.TestCase):

@ignore_warnings
def setUp(self):
global root
self.config = load_config()
self.pomodoro_frame = PomodoroFrame(None)

@ignore_warnings
def test_initialize_ui(self):
config = self.config
frame = self.pomodoro_frame
self.assertIsNotNone(frame)

self.assertIsNotNone(frame.break_text)
self.assertEqual(frame.pomodoro_time, config.get("pomodoro_time", DEF_POMODORO_MINS) * 60)
self.assertIsNotNone(frame.timer_display)
self.assertIsNotNone(frame.start_button)
self.assertIsNotNone(frame.start_button)
self.assertIsNotNone(frame.sb_button)
self.assertIsNotNone(frame.lb_button)
self.assertIsNotNone(frame.reset_button)

self.assertFalse(frame.running)
self.assertFalse(frame.break_running)
self.assertIsNone(frame.next_timer_update)
self.assertEqual(frame.remaining_time, frame.pomodoro_time)

self.assertEqual(frame.auto_break_cycling, config.get("auto_break_cycling", False))
self.assertEqual(frame.short_breaks_before_long, config.get("short_breaks_before_long", DEF_SB_BEFORE_L))
self.assertFalse(frame.short_break_running)
self.assertEqual(frame.short_break_counter, 0)

self.assertIsNone(frame.start_time_timestamp)
self.assertIsNone(frame.end_time_timestamp)

self.assertEqual(frame.session_counter, 0)
self.assertEqual(frame.seconds_studied, 0)

@ignore_warnings
def test_toggle_timer(self):
frame = self.pomodoro_frame
frame.toggle_timer()
self.assertTrue(frame.running)
self.assertIsNotNone(frame.start_time_timestamp)
self.assertIsNotNone(frame.end_time_timestamp)
frame.toggle_timer()
self.assertFalse(frame.running)

@ignore_warnings
def test_reset(self):
frame = self.pomodoro_frame
frame.running = True
frame.break_running = True
frame.short_break_running = True
frame.break_text.set("Short break")
frame.remaining_time = 100
frame.reset()
self.assertFalse(frame.running)
self.assertFalse(frame.break_running)
self.assertFalse(frame.short_break_running)
self.assertEqual(frame.break_text.get(), "")
self.assertEqual(frame.remaining_time, frame.pomodoro_time)

@ignore_warnings
def test_short_break(self):
frame = self.pomodoro_frame
frame.short_break()
self.assertTrue(frame.break_running)
self.assertTrue(frame.short_break_running)
self.assertEqual(frame.break_text.get(), "Short break")

@ignore_warnings
def test_long_break(self):
frame = self.pomodoro_frame
frame.long_break()
self.assertTrue(frame.break_running)
self.assertEqual(frame.break_text.get(), "Long break")
37 changes: 37 additions & 0 deletions pomodorodiscord/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import unittest
from src.utils import load_config, save_config, load_data, save_data


class TestUtils(unittest.TestCase):

def setUp(self):
self.saved_config = load_config()
self.saved_data = load_data()

def tearDown(self):
save_config(self.saved_config)
save_data(self.saved_data)

def test_load_config(self):
config = load_config()
self.assertIsInstance(config, dict)
self.assertIn('theme', config)
self.assertIn('sound', config)

def test_save_config(self):
config = {'theme': 'test_theme', 'sound': 'test_sound.mp3'}
save_config(config)
loaded_config = load_config()
self.assertEqual(config, loaded_config)

def test_load_data(self):
data = load_data()
self.assertIsInstance(data, dict)
self.assertIn('total_seconds_studied', data)
self.assertIn('total_pomodoro_sessions', data)

def test_save_data(self):
data = {'total_seconds_studied': 1000, 'total_pomodoro_sessions': 10}
save_data(data)
loaded_data = load_data()
self.assertEqual(data, loaded_data)

0 comments on commit a6dfb72

Please sign in to comment.