-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-131178: add unittest for turtledemo #139983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
45cb290
to
d4e86b8
Compare
d4e86b8
to
e835630
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you creating a faux unittest? Please use the actual module, I suggest you look at the many other tests in Lib/test/
.
self.passed = 0 | ||
self.failed = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we tracking this manually? Unittest reports it automatically?
def assert_true(self, condition, msg=""): | ||
if condition: | ||
self.passed += 1 | ||
print(f"✓ {msg}") | ||
else: | ||
self.failed += 1 | ||
print(f"✗ {msg}") | ||
|
||
def assert_equal(self, a, b, msg=""): | ||
if a == b: | ||
self.passed += 1 | ||
print(f"✓ {msg}") | ||
else: | ||
self.failed += 1 | ||
print(f"✗ {msg}: {a} != {b}") | ||
|
||
def assert_in(self, item, container, msg=""): | ||
if item in container: | ||
self.passed += 1 | ||
print(f"✓ {msg}") | ||
else: | ||
self.failed += 1 | ||
print(f"✗ {msg}: {item} not in {container}") | ||
|
||
def assert_is_instance(self, obj, expected_type, msg=""): | ||
if isinstance(obj, expected_type): | ||
self.passed += 1 | ||
print(f"✓ {msg}") | ||
else: | ||
self.failed += 1 | ||
print(f"✗ {msg}: {type(obj)} != {expected_type}") | ||
|
||
def assert_has_attr(self, obj, attr, msg=""): | ||
if hasattr(obj, attr): | ||
self.passed += 1 | ||
print(f"✓ {msg}") | ||
else: | ||
self.failed += 1 | ||
print(f"✗ {msg}: {attr} not found") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of these? Why not unittest methods, self.assertEqual
, self.assertTrue
and so on?
import importlib.util | ||
|
||
|
||
class SimpleTest: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is unittest not used? Can you please look at existing tests.
This test suite validates the CLI functionality of the turtledemo module, | ||
which provides a GUI-based demo viewer for turtle graphics examples. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test suite validates the CLI functionality of the turtledemo module, | |
which provides a GUI-based demo viewer for turtle graphics examples. |
If we test more than the CLI, this comment is wrong, I suggest removing it now.
def summary(self): | ||
total = self.passed + self.failed | ||
print(f"\nTest Summary: {self.passed}/{total} passed, {self.failed} failed") | ||
return self.failed == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this for? Unittest provides such results automatically? This is not called anywhere in your test either?
gh-131178: add unittest for turtledemo command line interface