Skip to content
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

tests: Improve xkeyboard-config script #503

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wismill
Copy link
Member

@wismill wismill commented Sep 5, 2024

  • Refactor to more modern Python
  • Allow iterating over models too
  • Add filter for models and options
  • Add “short output” option

- Refactor to more modern Python
- Allow iterating over models too
- Add filter for models and options
- Add “short output” option
@wismill wismill added enhancement Indicates new feature requests testing Indicates a need for improvements or additions to testing labels Sep 5, 2024
@wismill wismill added this to the 1.8.0 milestone Sep 5, 2024
Copy link
Contributor

@whot whot left a comment

Choose a reason for hiding this comment

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

just a few comments, none of which are very important

test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
test/xkeyboard-config-test.py.in Show resolved Hide resolved
test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
test/xkeyboard-config-test.py.in Show resolved Hide resolved
test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
@wismill wismill force-pushed the test/xkeyboard-config-test-enhancements branch from 73e1ce3 to ab679d3 Compare September 6, 2024 08:46
Copy link
Member Author

@wismill wismill left a comment

Choose a reason for hiding this comment

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

Refactored further. I would like to speed this up too.

test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
test/xkeyboard-config-test.py.in Show resolved Hide resolved
test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
test/xkeyboard-config-test.py.in Show resolved Hide resolved
test/xkeyboard-config-test.py.in Outdated Show resolved Hide resolved
Copy link
Member

@bluetech bluetech left a comment

Choose a reason for hiding this comment

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

Can't say I read it all, just a couple drive-by comments...

cast,
)

try:
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit: I know @whot suggested to use try/except for this, though in my experience the sys.version_info-style check is more common in Python, because it can be statically analyzed and can be automatically be removed when dropping support for old versions, while try/except need manual handling.

In this case, another alternative is to unconditionally do this:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
   from typing_extensions import Self


DEFAULT_RULES_XML = "@XKB_CONFIG_ROOT@/rules/evdev.xml"

# Meson needs to fill this in so we can call the tool in the buildir.
EXTRA_PATH = "@MESON_BUILD_ROOT@"
os.environ["PATH"] = ":".join([EXTRA_PATH, os.getenv("PATH")])

os.environ["PATH"] = ":".join(filter(None, (EXTRA_PATH, os.getenv("PATH"))))
Copy link
Member

Choose a reason for hiding this comment

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

I'm using Python for some time and didn't know filter(None, ...) was a thing :)

It might be a bit clearer to do

":".join(path for path in (EXTRA_PATH, os.getenv("PATH")) if path)

but the filter is OK too.

except ImportError:
pass
@property
def __iter__(self) -> Generator[str | None, None, None]:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def __iter__(self) -> Generator[str | None, None, None]:
def __iter__(self) -> Iterator[str | None]:

(the fact that it's a generator is an implementation detail)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Indicates new feature requests testing Indicates a need for improvements or additions to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants