Skip to content

Commit

Permalink
Add unit tests and GitHub Actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Hassan Shabbir Ahmed committed Nov 30, 2024
1 parent ee043ef commit c4ddbe7
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Python Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install Tkinter
run: |
sudo apt-get update
sudo apt-get install -y python3-tk
- name: Run tests
run: |
python -m unittest test_typing_speed.py -v
46 changes: 46 additions & 0 deletions test_typing_speed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import unittest
from main import TypingSpeedTest
import tkinter as tk

class TestTypingSpeedTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.root = tk.Tk()
cls.app = TypingSpeedTest(cls.root)

def setUp(self):
self.app.display_text.delete('1.0', tk.END)
self.app.current_text = ""
self.app.start_time = None
self.app.word_count = 25

def test_initial_state(self):
"""Test the initial state of the application"""
self.assertIsNone(self.app.start_time)
self.assertEqual(self.app.word_count, 25)
self.assertEqual(self.app.current_text, "")

def test_word_list(self):
"""Test that word list exists and is not empty"""
self.assertGreater(len(self.app.word_list), 0)
self.assertIsInstance(self.app.word_list, list)
self.assertTrue(all(isinstance(word, str) for word in self.app.word_list))

def test_window_properties(self):
"""Test window properties"""
self.assertEqual(self.app.root.title(), "Typing Speed Test")
# Check that geometry is set (format should be WxH or WxH+X+Y)
geometry = self.app.root.geometry()
self.assertRegex(geometry, r'\d+x\d+(?:\+\d+\+\d+)?')

def test_ui_elements(self):
"""Test that main UI elements exist"""
self.assertIsInstance(self.app.display_text, tk.Text)
self.assertIsInstance(self.app.text_frame, tk.Frame)

@classmethod
def tearDownClass(cls):
cls.root.destroy()

if __name__ == '__main__':
unittest.main()

0 comments on commit c4ddbe7

Please sign in to comment.