Skip to content

Commit 20c88e7

Browse files
committed
Add tests and change toml boolean values to lowercase
1 parent 6e9983b commit 20c88e7

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

qtpy/cli.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@ def generate_pyright_config_json():
4141
"""Generate Pyright config to be used in `pyrightconfig.json`."""
4242
apis_active = get_api_status()
4343

44-
return json.dumps({ "defineConstant": {name.upper(): is_active for name, is_active in apis_active.items()}})
44+
return json.dumps({
45+
"defineConstant": {name.upper(): is_active for name, is_active in apis_active.items()}
46+
})
4547

4648

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

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

5357

5458
def print_mypy_args():

qtpy/tests/test_cli.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import subprocess
44
import sys
5+
import textwrap
56

67
import pytest
78

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

7778
assert output.stdout.strip() == expected.strip()
79+
80+
def test_cli_pyright_config():
81+
output = subprocess.run(
82+
[sys.executable, '-m', 'qtpy', 'pyright-config'],
83+
capture_output=True,
84+
check=True,
85+
encoding='utf-8',
86+
)
87+
88+
if qtpy.PYQT5:
89+
expected = textwrap.dedent("""
90+
pyrightconfig.json:
91+
{"defineConstant": {"PYQT5": true, "PYSIDE2": false, "PYQT6": false, "PYSIDE6": false}}
92+
93+
pyproject.toml:
94+
[tool.pyright.defineConstant]
95+
PYQT5 = true
96+
PYSIDE2 = false
97+
PYQT6 = false
98+
PYSIDE6 = false
99+
""")
100+
elif qtpy.PYSIDE2:
101+
expected = textwrap.dedent("""
102+
pyrightconfig.json:
103+
{"defineConstant": {"PYQT5": false, "PYSIDE2": true, "PYQT6": false, "PYSIDE6": false}}
104+
105+
pyproject.toml:
106+
[tool.pyright.defineConstant]
107+
PYQT5 = false
108+
PYSIDE2 = true
109+
PYQT6 = false
110+
PYSIDE6 = false
111+
""")
112+
elif qtpy.PYQT6:
113+
expected = textwrap.dedent("""
114+
pyrightconfig.json:
115+
{"defineConstant": {"PYQT5": false, "PYSIDE2": false, "PYQT6": true, "PYSIDE6": false}}
116+
117+
pyproject.toml:
118+
[tool.pyright.defineConstant]
119+
PYQT5 = false
120+
PYSIDE2 = false
121+
PYQT6 = true
122+
PYSIDE6 = false
123+
""")
124+
elif qtpy.PYSIDE6:
125+
expected = textwrap.dedent("""
126+
pyrightconfig.json:
127+
{"defineConstant": {"PYQT5": false, "PYSIDE2": false, "PYQT6": false, "PYSIDE6": true}}
128+
129+
pyproject.toml:
130+
[tool.pyright.defineConstant]
131+
PYQT5 = false
132+
PYSIDE2 = false
133+
PYQT6 = false
134+
PYSIDE6 = true
135+
""")
136+
else:
137+
assert False, 'No valid API to test'
138+
139+
assert output.stdout.strip() == expected.strip()

0 commit comments

Comments
 (0)