Skip to content

Conversation

@LamentXU123
Copy link
Contributor

@LamentXU123LamentXU123 commented Jul 11, 2025

This PR add simple cli test cases to UUIDv6, v7, v8 added in #89083 , as well as a test case to UUID v1.

There are only one test cases for each, since they can't be customized through CLI.

Skipping news ;)

@LamentXU123LamentXU123 changed the title gh-89083: add cli tests for new UUID versionsgh-89083: Add cli tests for new UUID versionsJul 11, 2025
Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you:

  • follow PEP-8 (1 blank line between functions)
  • make a separate class that is only testing the CLI functionality please?

@LamentXU123LamentXU123 requested a review from picnixzJuly 11, 2025 16:11
@LamentXU123
Copy link
ContributorAuthor

LamentXU123 commented Jul 11, 2025

follow PEP-8 (1 blank line between functions)
make a separate class that is only testing the CLI functionality please?

Done. Thanks!

Edited: btw, we've got tested like this:

classTestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase): uuid=py_uuid

In this current PR code, this test in redundant. I suggest maybe we could combine them together (?)

self.assertIs(strong, weak())


class TestUUIDCli(BaseTestUUID, unittest.TestCase):
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all CAPS on term CLI?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just check how other classes testing CLIs are named.

Copy link
Member

@picnixzpicnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of duplicated code. I would sugfgest having a single a single function that tests the expected outputs accordingly:

defdo_test_standalone_uuid(self, version): stdout=io.StringIO() withcontextlib.redirect_stdout(stdout): self.uuid.main() output=stdout.getvalue().strip() u=self.uuid.UUID(output) self.assertEqual(output, str(u)) self.assertEqual(u.version, version) @mock.patch.object(sys, "argv", ["", "-u", "uuid1"])deftest_uuid1(self): self.do_test_standalone_uuid(1)

and similar stuff for v6, v7 and v8.

@LamentXU123
Copy link
ContributorAuthor

follow PEP-8 (1 blank line between functions)
make a separate class that is only testing the CLI functionality please?

Done. Thanks!

Edited: btw, we've got tested like this:

classTestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase): uuid=py_uuid

In this current PR code, this test in redundant. I suggest maybe we could combine them together (?)

In the test case of cli we've actually already tested UUID without ext moudle (?, I'm not quiet sure) So maybe combining them together will be better?

self.assertIs(strong, weak())


class TestUUIDCli(BaseTestUUID, unittest.TestCase):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just check how other classes testing CLIs are named.

@picnixz
Copy link
Member

In the test case of cli we've actually already tested UUID without ext moudle (?, I'm not quiet sure) So maybe combining them together will be better?

In this current PR code, this test in redundant. I suggest maybe we could combine them together (?)

It's not entirely redundant. However I see the issue. Two possibilities:

  • Make the CLI test a mixin class that doesn't inherit from test case
  • Create two subclasses that are test cases, one with the extension module, one without.

Or:

  • Make CLI tests a mixin class that doesn't inhert from test cases, without a uuid field (you can add a dummy one just for autocompletion, but set it to None as it'll be subclassed later).
  • Make TestUUIDWithoutExtModule and TestUUIDWithExtModule inherit from this mixin as well (in addition to BaseTestUUID).

@picnixz
Copy link
Member

picnixz commented Jul 11, 2025

Ok, actually CommandLineTest is a more common name in the code base. Just use it, no need to mention UUID (search for "CommandLineTest" and you'll see)

@LamentXU123
Copy link
ContributorAuthor

Ok, actually CommandLineTest is a more common name in the code base. Just use it, no need to mention UUID (search for "CommandLineTest" and you'll see)

The test classes before are named in testUUID* (which I think would be better if we add this prefix in this func). But yes CommandLineTest only is more common one in the code base so it's OK.

@LamentXU123
Copy link
ContributorAuthor

Make the CLI test a mixin class that doesn't inherit from test case
Create two subclasses that are test cases, one with the extension module, one without.

This is better IMO. I've changed it.

Co-authored-by: Bénédikt Tran <[email protected]>
@picnixzpicnixz changed the title gh-89083: Add cli tests for new UUID versionsgh-89083: Add CLI tests for UUIDv{6,7,8}Jul 11, 2025
@picnixzpicnixz changed the title gh-89083: Add CLI tests for UUIDv{6,7,8}gh-89083: Add CLI tests for UUIDv{6,7,8}Jul 11, 2025
@picnixzpicnixz merged commit c564847 into python:mainJul 12, 2025
43 checks passed
@LamentXU123
Copy link
ContributorAuthor

Thanks! Should we backport this to 3.14? The new UUIDs are added in that version

@picnixzpicnixz added the needs backport to 3.14 bugs and security fixes label Jul 12, 2025
@miss-islington-app
Copy link

Thanks @LamentXU123 for the PR, and @picnixz for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 12, 2025
(cherry picked from commit c564847) Co-authored-by: Weilin Du <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
@bedevere-app
Copy link

GH-136576 is a backport of this pull request to the 3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14 bugs and security fixes label Jul 12, 2025
picnixz added a commit that referenced this pull request Jul 12, 2025
gh-89083: Add CLI tests for `UUIDv{6,7,8}` (GH-136548) (cherry picked from commit c564847) Co-authored-by: Weilin Du <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
picnixz added a commit to picnixz/cpython that referenced this pull request Jul 13, 2025
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
kumaraditya303 pushed a commit to miss-islington/cpython that referenced this pull request Sep 9, 2025
) (python#136576) pythongh-89083: Add CLI tests for `UUIDv{6,7,8}` (pythonGH-136548) (cherry picked from commit c564847) Co-authored-by: Weilin Du <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip newstestsTests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@LamentXU123@picnixz@StanFromIreland