File: cmdline.pyproject.test

package info (click to toggle)
mypy 1.19.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,412 kB
  • sloc: python: 114,754; ansic: 13,343; cpp: 11,380; makefile: 257; sh: 28
file content (239 lines) | stat: -rw-r--r-- 5,610 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
-- Tests for command line parsing
-- ------------------------------
--
-- The initial line specifies the command line, in the format
--
--   # cmd: mypy <options>
--
-- Note that # flags: --some-flag IS NOT SUPPORTED.
-- Use # cmd: mypy --some-flag ...
--
-- '== Return code: <value>' is added to the output when the process return code
-- is "nonobvious" -- that is, when it is something other than 0 if there are no
-- messages and 1 if there are.

-- Directories/packages on the command line
-- ----------------------------------------

[case testNonArrayOverridesPyprojectTOML]
# cmd: mypy x.py
[file pyproject.toml]
\[tool.mypy]
\[tool.mypy.overrides]
module = "x"
disallow_untyped_defs = false
[file x.py]
def f(a):
    pass
def g(a: int) -> int:
    return f(a)
[out]
pyproject.toml: tool.mypy.overrides sections must be an array. Please make sure you are using double brackets like so: [[tool.mypy.overrides]]
== Return code: 0

[case testNoModuleInOverridePyprojectTOML]
# cmd: mypy x.py
[file pyproject.toml]
\[tool.mypy]
\[[tool.mypy.overrides]]
disallow_untyped_defs = false
[file x.py]
def f(a):
    pass
def g(a: int) -> int:
    return f(a)
[out]
pyproject.toml: toml config file contains a [[tool.mypy.overrides]] section, but no module to override was specified.
== Return code: 0

[case testInvalidModuleInOverridePyprojectTOML]
# cmd: mypy x.py
[file pyproject.toml]
\[tool.mypy]
\[[tool.mypy.overrides]]
module = 0
disallow_untyped_defs = false
[file x.py]
def f(a):
    pass
def g(a: int) -> int:
    return f(a)
[out]
pyproject.toml: toml config file contains a [[tool.mypy.overrides]] section with a module value that is not a string or a list of strings
== Return code: 0

[case testConflictingModuleInOverridesPyprojectTOML]
# cmd: mypy x.py
[file pyproject.toml]
\[tool.mypy]
\[[tool.mypy.overrides]]
module = 'x'
disallow_untyped_defs = false
\[[tool.mypy.overrides]]
module = ['x']
disallow_untyped_defs = true
[file x.py]
def f(a):
    pass
def g(a: int) -> int:
    return f(a)
[out]
pyproject.toml: toml config file contains [[tool.mypy.overrides]] sections with conflicting values. Module 'x' has two different values for 'disallow_untyped_defs'
== Return code: 0

[case testMultilineLiteralExcludePyprojectTOML]
# cmd: mypy x
[file pyproject.toml]
\[tool.mypy]
exclude = '''(?x)(
    (^|/)[^/]*skipme_\.py$
    |(^|/)_skipme[^/]*\.py$
)'''
[file x/__init__.py]
i: int = 0
[file x/_skipme_please.py]
This isn't even syntactically valid!
[file x/please_skipme_.py]
Neither is this!

[case testMultilineBasicExcludePyprojectTOML]
# cmd: mypy x
[file pyproject.toml]
\[tool.mypy]
exclude = """(?x)(
    (^|/)[^/]*skipme_\\.py$
    |(^|/)_skipme[^/]*\\.py$
)"""
[file x/__init__.py]
i: int = 0
[file x/_skipme_please.py]
This isn't even syntactically valid!
[file x/please_skipme_.py]
Neither is this!

[case testSequenceExcludePyprojectTOML]
# cmd: mypy x
[file pyproject.toml]
\[tool.mypy]
exclude = [
    '(^|/)[^/]*skipme_\.py$',  # literal (no escaping)
    "(^|/)_skipme[^/]*\\.py$",  # basic (backslash needs escaping)
]
[file x/__init__.py]
i: int = 0
[file x/_skipme_please.py]
This isn't even syntactically valid!
[file x/please_skipme_.py]
Neither is this!

[case testPyprojectTOMLUnicode]
# cmd: mypy x.py
[file pyproject.toml]
\[project]
description = "Factory ⸻ A code generator 🏭"
\[tool.mypy]
[file x.py]

[case testPyprojectFilesTrailingComma]
# cmd: mypy
[file pyproject.toml]
\[tool.mypy]
# We combine multiple tests in a single one here, because these tests are slow.
files = """
  a.py,
  b.py,
"""
always_true = """
  FLAG_A1,
  FLAG_B1,
"""
always_false = """
  FLAG_A2,
  FLAG_B2,
"""
[file a.py]
x: str = 'x'  # ok'

# --always-true
FLAG_A1 = False
FLAG_B1 = False
if not FLAG_A1:  # unreachable
    x: int = 'x'
if not FLAG_B1:  # unreachable
    y: int = 'y'

# --always-false
FLAG_A2 = True
FLAG_B2 = True
if FLAG_A2:  # unreachable
    x: int = 'x'
if FLAG_B2:  # unreachable
    y: int = 'y'
[file b.py]
y: int = 'y'  # E: Incompatible types in assignment (expression has type "str", variable has type "int")
[file c.py]
# This should not trigger any errors, because it is not included:
z: int = 'z'
[out]

[case testPyprojectModulesTrailingComma]
# cmd: mypy
[file pyproject.toml]
\[tool.mypy]
# We combine multiple tests in a single one here, because these tests are slow.
modules = """
  a,
  b,
"""
disable_error_code = """
  operator,
  import,
"""
enable_error_code = """
  redundant-expr,
  ignore-without-code,
"""
[file a.py]
x: str = 'x'  # ok

# --enable-error-code
a: int = 'a'  # type: ignore

# --disable-error-code
'a' + 1
[file b.py]
y: int = 'y'
[file c.py]
# This should not trigger any errors, because it is not included:
z: int = 'z'
[out]
b.py:1: error: Incompatible types in assignment (expression has type "str", variable has type "int")
a.py:4: error: "type: ignore" comment without error code (consider "type: ignore[assignment]" instead)

[case testPyprojectPackagesTrailingComma]
# cmd: mypy
[file pyproject.toml]
\[tool.mypy]
packages = """
  a,
  b,
"""
[file a/__init__.py]
x: str = 'x'  # ok
[file b/__init__.py]
y: int = 'y'  # E: Incompatible types in assignment (expression has type "str", variable has type "int")
[file c/__init__.py]
# This should not trigger any errors, because it is not included:
z: int = 'z'
[out]

[case testPyprojectTOMLSettingOfWrongType]
# cmd: mypy a.py
[file pyproject.toml]
\[tool.mypy]
enable_error_code = true
[file a.py]
x: int = 1
[out]
pyproject.toml: [mypy]: enable_error_code: Expected a list or a stringified version thereof, but got: 'True', of type bool.
== Return code: 0