-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_new_filters.py
More file actions
121 lines (96 loc) · 4.86 KB
/
test_new_filters.py
File metadata and controls
121 lines (96 loc) · 4.86 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3
"""
Test script for the new filter functionality
"""
import unittest
import tkinter as tk
from git_repository_manager import GitRepositoryManager
class TestFilterOptions(unittest.TestCase):
def setUp(self):
"""Set up test fixtures"""
# Create a minimal GitRepositoryManager instance for testing
self.root = tk.Tk()
self.app = GitRepositoryManager()
def tearDown(self):
"""Clean up after tests"""
self.root.destroy()
def test_text_matches_simple(self):
"""Test simple text matching"""
# Test case insensitive by default
self.app.match_case.set(False)
self.app.match_whole_word.set(False)
self.app.use_regex.set(False)
self.assertTrue(self.app._text_matches("Hello World", "hello"))
self.assertTrue(self.app._text_matches("Hello World", "world"))
self.assertFalse(self.app._text_matches("Hello World", "xyz"))
def test_text_matches_case_sensitive(self):
"""Test case sensitive matching"""
self.app.match_case.set(True)
self.app.match_whole_word.set(False)
self.app.use_regex.set(False)
self.assertTrue(self.app._text_matches("Hello World", "Hello"))
self.assertFalse(self.app._text_matches("Hello World", "hello"))
self.assertTrue(self.app._text_matches("Hello World", "World"))
self.assertFalse(self.app._text_matches("Hello World", "world"))
def test_text_matches_whole_word(self):
"""Test whole word matching"""
self.app.match_case.set(False)
self.app.match_whole_word.set(True)
self.app.use_regex.set(False)
self.assertTrue(self.app._text_matches("Hello World", "hello"))
self.assertTrue(self.app._text_matches("Hello World", "world"))
self.assertFalse(self.app._text_matches("Hello World", "ell")) # Partial word
self.assertFalse(self.app._text_matches("Hello World", "orl")) # Partial word
def test_text_matches_regex(self):
"""Test regex matching"""
self.app.match_case.set(False)
self.app.match_whole_word.set(False)
self.app.use_regex.set(True)
self.assertTrue(self.app._text_matches("Hello World", "h.*o"))
self.assertTrue(self.app._text_matches("Hello World", "w.+d"))
self.assertFalse(self.app._text_matches("Hello World", "^world")) # Should not match
self.assertTrue(self.app._text_matches("Hello World", "world$")) # Should match
def test_text_matches_regex_case_sensitive(self):
"""Test regex matching with case sensitivity"""
self.app.match_case.set(True)
self.app.match_whole_word.set(False)
self.app.use_regex.set(True)
self.assertTrue(self.app._text_matches("Hello World", "H.*o"))
self.assertFalse(self.app._text_matches("Hello World", "h.*o"))
def test_text_matches_regex_whole_word(self):
"""Test regex matching with whole word"""
self.app.match_case.set(False)
self.app.match_whole_word.set(True)
self.app.use_regex.set(True)
self.assertTrue(self.app._text_matches("Hello World", "hello"))
self.assertFalse(self.app._text_matches("Hello World", "ell"))
def test_text_matches_empty_pattern(self):
"""Test matching with empty pattern"""
self.app.match_case.set(False)
self.app.match_whole_word.set(False)
self.app.use_regex.set(False)
# Empty pattern should match everything
self.assertTrue(self.app._text_matches("Hello World", ""))
self.assertTrue(self.app._text_matches("", ""))
def test_text_matches_empty_text(self):
"""Test matching with empty text"""
self.app.match_case.set(False)
self.app.match_whole_word.set(False)
self.app.use_regex.set(False)
# Non-empty pattern should not match empty text
self.assertFalse(self.app._text_matches("", "hello"))
self.assertTrue(self.app._text_matches("", ""))
def test_ui_elements_exist(self):
"""Test that all new UI elements are created"""
# Check that the new filter option variables exist
self.assertIsNotNone(self.app.match_case)
self.assertIsNotNone(self.app.match_whole_word)
self.assertIsNotNone(self.app.use_regex)
self.assertIsNotNone(self.app.search_scope)
# Check default values
self.assertFalse(self.app.match_case.get())
self.assertFalse(self.app.match_whole_word.get())
self.assertFalse(self.app.use_regex.get())
self.assertEqual(self.app.search_scope.get(), "remote and local")
if __name__ == '__main__':
unittest.main()