Skip to content

gh-89083: Add CLI tests for UUIDv{6,7,8} #136548

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

Merged
merged 13 commits into from
Jul 12, 2025

Conversation

LamentXU123
Copy link
Contributor

@LamentXU123 LamentXU123 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 ;)

@LamentXU123 LamentXU123 changed the title gh-89083: add cli tests for new UUID versions gh-89083: Add cli tests for new UUID versions Jul 11, 2025
Copy link
Member

@picnixz picnixz 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?

@LamentXU123 LamentXU123 requested a review from picnixz July 11, 2025 16:11
@LamentXU123
Copy link
Contributor Author

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:

class TestUUIDWithoutExtModule(BaseTestUUID, unittest.TestCase):
    uuid = py_uuid

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

@@ -1140,6 +1140,9 @@ def test_uuid_weakref(self):
weak = weakref.ref(strong)
self.assertIs(strong, weak())


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

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

@picnixz picnixz 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:

def do_test_standalone_uuid(self, version):
    stdout = io.StringIO()
    with contextlib.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"])
def test_uuid1(self):
    self.do_test_standalone_uuid(1)

and similar stuff for v6, v7 and v8.

@LamentXU123
Copy link
Contributor Author

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:

class TestUUIDWithoutExtModule(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?

@@ -1140,6 +1140,9 @@ def test_uuid_weakref(self):
weak = weakref.ref(strong)
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

picnixz commented Jul 11, 2025

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
Contributor Author

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
Contributor Author

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 <10796600+picnixz@users.noreply.github.com>
@picnixz picnixz changed the title gh-89083: Add cli tests for new UUID versions gh-89083: Add CLI tests for UUIDv{6,7,8} Jul 11, 2025
@picnixz picnixz 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
@picnixz picnixz merged commit c564847 into python:main Jul 12, 2025
43 checks passed
@LamentXU123
Copy link
Contributor Author

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

@picnixz picnixz 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 <108666168+LamentXU123@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Jul 12, 2025

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

@bedevere-app bedevere-app bot 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 <108666168+LamentXU123@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy