-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests and GitHub Actions workflow
- Loading branch information
Hassan Shabbir Ahmed
committed
Nov 30, 2024
1 parent
ee043ef
commit c4ddbe7
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |