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

Improve system tests #188

Open
meator opened this issue Nov 22, 2024 · 0 comments
Open

Improve system tests #188

meator opened this issue Nov 22, 2024 · 0 comments

Comments

@meator
Copy link
Collaborator

meator commented Nov 22, 2024

I have been working on this feature for some time now. It requires more work though and I don't want to delay r3.2 further.

The current pytest testsuite is written in a DRY fashion. It is not really readable because of this. A solution I have been toying with is making a YAML file which would define all tests and their environment. This file would be more readable than the current Python code. Here is an example of how such a file could look like:

description: "Test --help flag"
test: exit_status
args: [--help]
---
description: Test --version flag
test: exit_status
args: [--version]
---
# TODO: chdir
description: Regression test faulty SearchPath checks
test: exit_status
environmental_variables:
  XDG_DATA_HOME: "$empty_directory$"
  XDG_DATA_DIRS: .:a:b
args: [--version]
---
description:
  Test j4-dmenu-desktop's integration with its supported terminal emulators
parametrize_from_dict: "#terminal-emulator-matrix#"
parametrize_skip:
  # TODO: Maybe unify two dicts
  - terminator:
      skip_message: See https://github.com/gnome-terminator/terminator/issues/923
condition:
  function: check_term_emulator_availability
  kw_args:
    terminal_name: "@parametrize.terminal_name@"
    commandline_flag: "@parametrize.commandline_flag@"
test:
  type: external_function
  function: test_term_emulator
  kw_args:
    tested_string: "#bad-strings#"
environmental_variables:
  PATH: "$helpers_path$:$PATH_list$"
  XDG_DATA_HOME: "$test_files$"
  XDG_DATA_DIRS: "$empty_directory$"
args: [--dmenu, "$dmenu_selected_imitator_helper$", --term-mode, "@parametrize@", --strict]

I make use of pytest's capabilities of testing non-Python code to read YAML and convert into unit tests. The tests themselves (mainly the more complicated ones) would be defined in a separate definitions.py file that would only include the testing function, which would receive a J4ddExecutor Python class instance which would have environment prefilled from the YAML file.

I wonder if there's a good library/framework for this. My solution would triple the code size for tests/system_tests/, but the definition files would be cleaner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant