Skip to content

Commit

Permalink
Add tests and change toml boolean values to lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
krokosik committed Aug 24, 2023
1 parent 6e9983b commit 20c88e7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
8 changes: 6 additions & 2 deletions qtpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ def generate_pyright_config_json():
"""Generate Pyright config to be used in `pyrightconfig.json`."""
apis_active = get_api_status()

return json.dumps({ "defineConstant": {name.upper(): is_active for name, is_active in apis_active.items()}})
return json.dumps({
"defineConstant": {name.upper(): is_active for name, is_active in apis_active.items()}
})


def generate_pyright_config_toml():
"""Generate a Pyright config to be used in `pyproject.toml`."""
apis_active = get_api_status()

return "[tool.pyright.defineConstant]\n" + "\n".join(f"{name.upper()} = {is_active}" for name, is_active in apis_active.items())
return "[tool.pyright.defineConstant]\n" + "\n".join(
f"{name.upper()} = {str(is_active).lower()}" for name, is_active in apis_active.items()
)


def print_mypy_args():
Expand Down
62 changes: 62 additions & 0 deletions qtpy/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import subprocess
import sys
import textwrap

import pytest

Expand Down Expand Up @@ -75,3 +76,64 @@ def test_cli_mypy_args():
assert False, 'No valid API to test'

assert output.stdout.strip() == expected.strip()

def test_cli_pyright_config():
output = subprocess.run(
[sys.executable, '-m', 'qtpy', 'pyright-config'],
capture_output=True,
check=True,
encoding='utf-8',
)

if qtpy.PYQT5:
expected = textwrap.dedent("""
pyrightconfig.json:
{"defineConstant": {"PYQT5": true, "PYSIDE2": false, "PYQT6": false, "PYSIDE6": false}}
pyproject.toml:
[tool.pyright.defineConstant]
PYQT5 = true
PYSIDE2 = false
PYQT6 = false
PYSIDE6 = false
""")
elif qtpy.PYSIDE2:
expected = textwrap.dedent("""
pyrightconfig.json:
{"defineConstant": {"PYQT5": false, "PYSIDE2": true, "PYQT6": false, "PYSIDE6": false}}
pyproject.toml:
[tool.pyright.defineConstant]
PYQT5 = false
PYSIDE2 = true
PYQT6 = false
PYSIDE6 = false
""")
elif qtpy.PYQT6:
expected = textwrap.dedent("""
pyrightconfig.json:
{"defineConstant": {"PYQT5": false, "PYSIDE2": false, "PYQT6": true, "PYSIDE6": false}}
pyproject.toml:
[tool.pyright.defineConstant]
PYQT5 = false
PYSIDE2 = false
PYQT6 = true
PYSIDE6 = false
""")
elif qtpy.PYSIDE6:
expected = textwrap.dedent("""
pyrightconfig.json:
{"defineConstant": {"PYQT5": false, "PYSIDE2": false, "PYQT6": false, "PYSIDE6": true}}
pyproject.toml:
[tool.pyright.defineConstant]
PYQT5 = false
PYSIDE2 = false
PYQT6 = false
PYSIDE6 = true
""")
else:
assert False, 'No valid API to test'

assert output.stdout.strip() == expected.strip()

0 comments on commit 20c88e7

Please sign in to comment.