Skip to content

Commit d06fca1

Browse files
committed
Improving universal selector test
1 parent 46fc178 commit d06fca1

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

tests/test_query.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class App(Widget):
5959
assert list(app.query("View#main")) == [main_view]
6060
assert list(app.query("View2#help")) == [help_view]
6161
assert list(app.query("#widget1")) == [widget1]
62-
assert list(app.query("#Widget1")) == [] # Note case.
62+
assert list(app.query("#Widget1")) == [] # Note case.
6363
assert list(app.query("#widget2")) == [widget2]
64-
assert list(app.query("#Widget2")) == [] # Note case.
64+
assert list(app.query("#Widget2")) == [] # Note case.
6565

6666
assert list(app.query("Widget.float")) == [sidebar, tooltip, helpbar]
6767
assert list(app.query(Widget).filter(".float")) == [sidebar, tooltip, helpbar]
@@ -131,14 +131,13 @@ class App(Widget):
131131

132132

133133
def test_query_classes():
134-
135134
class App(Widget):
136135
pass
137136

138137
class ClassTest(Widget):
139138
pass
140139

141-
CHILD_COUNT=100
140+
CHILD_COUNT = 100
142141

143142
# Create a fake app to hold everything else.
144143
app = App()
@@ -148,34 +147,35 @@ class ClassTest(Widget):
148147
app._add_child(ClassTest(id=f"child{n}"))
149148

150149
# Let's just be 100% sure everything was created fine.
151-
assert len(app.query(ClassTest))==CHILD_COUNT
150+
assert len(app.query(ClassTest)) == CHILD_COUNT
152151

153152
# Now, let's check there are *no* children with the test class.
154-
assert len(app.query(".test"))==0
153+
assert len(app.query(".test")) == 0
155154

156155
# Add the test class to everything and then check again.
157156
app.query(ClassTest).add_class("test")
158-
assert len(app.query(".test"))==CHILD_COUNT
157+
assert len(app.query(".test")) == CHILD_COUNT
159158

160159
# Remove the test class from everything then try again.
161160
app.query(ClassTest).remove_class("test")
162-
assert len(app.query(".test"))==0
161+
assert len(app.query(".test")) == 0
163162

164163
# Add the test class to everything using set_class.
165164
app.query(ClassTest).set_class(True, "test")
166-
assert len(app.query(".test"))==CHILD_COUNT
165+
assert len(app.query(".test")) == CHILD_COUNT
167166

168167
# Remove the test class from everything using set_class.
169168
app.query(ClassTest).set_class(False, "test")
170-
assert len(app.query(".test"))==0
169+
assert len(app.query(".test")) == 0
171170

172171
# Add the test class to everything using toggle_class.
173172
app.query(ClassTest).toggle_class("test")
174-
assert len(app.query(".test"))==CHILD_COUNT
173+
assert len(app.query(".test")) == CHILD_COUNT
175174

176175
# Remove the test class from everything using toggle_class.
177176
app.query(ClassTest).toggle_class("test")
178-
assert len(app.query(".test"))==0
177+
assert len(app.query(".test")) == 0
178+
179179

180180
def test_invalid_query():
181181
class App(Widget):
@@ -210,3 +210,4 @@ def compose(self) -> ComposeResult:
210210
query = container.query("*")
211211
results = list(query.results())
212212
assert len(results) == 5
213+
assert not any(node.id == "root-container" for node in results)

0 commit comments

Comments
 (0)