Skip to content

Commit 03b7e3c

Browse files
committed
Fix linting
1 parent 938eec7 commit 03b7e3c

File tree

3 files changed

+78
-46
lines changed

3 files changed

+78
-46
lines changed

tested/languages/cpp/generators.py

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ def convert_type(self, value: Expression) -> str:
6262
return self.convert_declaration(value.type, value)
6363

6464
def combine_types(self, expressions: list[Expression]) -> str:
65-
content_types = set(self.convert_type(content) for content in expressions)
66-
if len(content_types) == 1:
67-
return content_types.pop()
68-
elif len(content_types) > 1:
69-
return f"std::variant<{', '.join(content_types)}>"
70-
else:
71-
return "std::any"
65+
content_types = set(self.convert_type(content) for content in expressions)
66+
if len(content_types) == 1:
67+
return content_types.pop()
68+
elif len(content_types) > 1:
69+
return f"std::variant<{', '.join(content_types)}>"
70+
else:
71+
return "std::any"
7272

7373
def sequence_subtype(self, value: Statement) -> str:
7474
if isinstance(value, SequenceType):
7575
return self.combine_types(value.data)
7676
else:
7777
return "std::any"
7878

79-
def convert_value(self, value: Value, add_type = False) -> str:
79+
def convert_value(self, value: Value, add_type=False) -> str:
8080
basic = as_basic_type(value)
8181
if add_type:
8282
tp = value.type
@@ -87,12 +87,14 @@ def convert_value(self, value: Value, add_type = False) -> str:
8787
if bt == BasicNothingTypes.NOTHING:
8888
return value_string
8989

90-
if (tp == AdvancedNumericTypes.DOUBLE_EXTENDED
90+
if (
91+
tp == AdvancedNumericTypes.DOUBLE_EXTENDED
9192
or tp == AdvancedNumericTypes.DOUBLE_PRECISION
9293
or tp == AdvancedNumericTypes.SINGLE_PRECISION
9394
or tp == AdvancedStringTypes.CHAR
9495
or bt == BasicBooleanTypes.BOOLEAN
95-
or bt == BasicNumericTypes.REAL):
96+
or bt == BasicNumericTypes.REAL
97+
):
9698
return f"(({type_string}) {value_string})"
9799

98100
return f"{type_string}({value_string})"
@@ -116,7 +118,8 @@ def convert_value(self, value: Value, add_type = False) -> str:
116118
+ "}"
117119
)
118120
elif (
119-
basic.type == BasicSequenceTypes.SEQUENCE or basic.type == BasicSequenceTypes.SET
121+
basic.type == BasicSequenceTypes.SEQUENCE
122+
or basic.type == BasicSequenceTypes.SET
120123
):
121124
return (
122125
"{"
@@ -195,7 +198,9 @@ def convert_declaration(
195198
return f"std::vector<{self.sequence_subtype(value)}>"
196199
elif tp == AdvancedSequenceTypes.TUPLE:
197200
if isinstance(value, SequenceType):
198-
subtype_string = ", ".join(self.convert_type(content) for content in value.data)
201+
subtype_string = ", ".join(
202+
self.convert_type(content) for content in value.data
203+
)
199204
return f"std::tuple<{subtype_string}>"
200205
else:
201206
return "std::tuple<std::any>"
@@ -226,7 +231,7 @@ def convert_declaration(
226231
return "void"
227232
raise AssertionError(f"Unknown type: {tp!r}")
228233

229-
def convert_statement(self, statement: Statement, add_value_type = False) -> str:
234+
def convert_statement(self, statement: Statement, add_value_type=False) -> str:
230235
if isinstance(statement, PropertyAssignment):
231236
return (
232237
f"{self.convert_statement(statement.property)} = "
@@ -248,7 +253,11 @@ def convert_statement(self, statement: Statement, add_value_type = False) -> str
248253
raise AssertionError(f"Unknown statement: {statement!r}")
249254

250255
def is_pascal_case(self, identifier: Identifier) -> bool:
251-
return len(identifier) > 0 and identifier[0].isupper() and not identifier[1:].isupper()
256+
return (
257+
len(identifier) > 0
258+
and identifier[0].isupper()
259+
and not identifier[1:].isupper()
260+
)
252261

253262
def convert_function_call(self, function: FunctionCall) -> str:
254263
result = function.name
@@ -273,13 +282,17 @@ def convert_function_call(self, function: FunctionCall) -> str:
273282
else:
274283
result = f"{function.namespace}.{result}"
275284
else:
276-
result = "(" + self.convert_statement(function.namespace) + ")." + result
285+
result = (
286+
"(" + self.convert_statement(function.namespace) + ")." + result
287+
)
277288
return result
278289

279290
def spacing(self, depth):
280291
return " " * depth * 4
281292

282-
def convert_testcase(self, tc: PreparedTestcase, pu: PreparedExecutionUnit, depth = 1) -> str:
293+
def convert_testcase(
294+
self, tc: PreparedTestcase, pu: PreparedExecutionUnit, depth=1
295+
) -> str:
283296
indent = self.spacing(depth)
284297
result = ""
285298
if tc.testcase.is_main_testcase():
@@ -320,17 +333,23 @@ def generate_internal_context(
320333
# Generate code for each testcase
321334
tc: PreparedTestcase
322335
for i, tc in enumerate(ctx.testcases):
323-
result += self.spacing(i+1) + "try {" + "\n"
324-
result += self.spacing(i+2) + f"{pu.unit.name}_write_separator();\n"
325-
result += self.convert_testcase(tc, pu, i+2)
326-
327-
for i in range(len(ctx.testcases), 0, -1):
328-
result += self.spacing(i) + "} catch (...) {\n"
329-
result += self.spacing(i+1) + "const std::exception_ptr &e = std::current_exception();\n"
330-
result += self.spacing(i+1) + self.convert_statement(
331-
tc.exception_statement("e")) + ";\n"
332-
result += self.spacing(i+1)+ "exit_code = 1;\n"
333-
result += self.spacing(i) + "}\n"
336+
result += self.spacing(i + 1) + "try {" + "\n"
337+
result += self.spacing(i + 2) + f"{pu.unit.name}_write_separator();\n"
338+
result += self.convert_testcase(tc, pu, i + 2)
339+
340+
for i in range(len(ctx.testcases) - 1, -1, -1):
341+
result += self.spacing(i + 1) + "} catch (...) {\n"
342+
result += (
343+
self.spacing(i + 2)
344+
+ "const std::exception_ptr &e = std::current_exception();\n"
345+
)
346+
result += (
347+
self.spacing(i + 2)
348+
+ self.convert_statement(ctx.testcases[i].exception_statement("e"))
349+
+ ";\n"
350+
)
351+
result += self.spacing(i + 2) + "exit_code = 1;\n"
352+
result += self.spacing(i + 1) + "}\n"
334353

335354
result += self.spacing(1) + ctx.after + "\n"
336355
result += self.spacing(1) + "return exit_code;\n"
@@ -460,7 +479,10 @@ def convert_encoder(self, values: list[Value]) -> str:
460479
int main() {
461480
"""
462481
for value in values:
463-
result += self.spacing(1) + f"write_value(std::cout, {self.convert_value(value, True)});\n"
482+
result += (
483+
self.spacing(1)
484+
+ f"write_value(std::cout, {self.convert_value(value, True)});\n"
485+
)
464486
result += self.spacing(1) + 'std::cout << "␞";\n'
465487
result += "}\n"
466488
return result

tests/test_language_quircks.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,45 +25,61 @@
2525
from tested.testsuite import Suite
2626
from tests.manual_utils import assert_valid_output, configuration, execute_config
2727

28+
2829
def test_cpp_function_assignment(tmp_path: Path, pytestconfig: pytest.Config):
2930
statement_string = "test: string = foo()"
3031
cpp = LANGUAGES["cpp"](pytestconfig)
3132
result = cpp.generate_statement(parse_string(statement_string))
3233

3334
assert result == "std::string test = foo()"
3435

36+
3537
def test_cpp_complex_function_assignment(tmp_path: Path, pytestconfig: pytest.Config):
36-
statement_string = "test = { \"a\": foo() }"
38+
statement_string = 'test = { "a": foo() }'
3739
cpp = LANGUAGES["cpp"](pytestconfig)
3840
result = cpp.generate_statement(parse_string(statement_string))
3941

40-
assert result == "std::map<std::string, std::any> test = {{\"a\", foo()}}"
42+
assert result == 'std::map<std::string, std::any> test = {{"a", foo()}}'
4143

42-
def test_cpp_types_get_cast_within_functions(tmp_path: Path, pytestconfig: pytest.Config):
43-
statement_string = "test: string = foo(1, \"2\", [3, 4], (5, 6), {7: 8})"
44+
45+
def test_cpp_types_get_cast_within_functions(
46+
tmp_path: Path, pytestconfig: pytest.Config
47+
):
48+
statement_string = 'test: string = foo(1, "2", [3, 4], (5, 6), {7: 8})'
4449
cpp = LANGUAGES["cpp"](pytestconfig)
4550
result = cpp.generate_statement(parse_string(statement_string))
4651

4752
int_p = "std::intmax_t(1)"
48-
str_p = "std::string(\"2\")"
53+
str_p = 'std::string("2")'
4954
vec_p = "std::vector<std::intmax_t>({3, 4})"
5055
tuple_p = "std::tuple<std::intmax_t, std::intmax_t>({5, 6})"
5156
map_p = "std::map<std::intmax_t, std::intmax_t>({{7, 8}})"
52-
assert result == f"std::string test = foo({int_p}, {str_p}, {vec_p}, {tuple_p}, {map_p})"
57+
assert (
58+
result
59+
== f"std::string test = foo({int_p}, {str_p}, {vec_p}, {tuple_p}, {map_p})"
60+
)
61+
5362

5463
def test_cpp_complex_type_assignment(tmp_path: Path, pytestconfig: pytest.Config):
5564
statement_string = "test = {'1': [2 , (3, {4, 5})]}"
5665
cpp = LANGUAGES["cpp"](pytestconfig)
5766
result = cpp.generate_statement(parse_string(statement_string))
5867

59-
variant_types = ["std::intmax_t", "std::tuple<std::intmax_t, std::set<std::intmax_t>>"]
68+
variant_types = [
69+
"std::intmax_t",
70+
"std::tuple<std::intmax_t, std::set<std::intmax_t>>",
71+
]
6072
permutations = list(itertools.permutations(variant_types))
61-
valid_types = [f"std::map<std::string, std::vector<std::variant<{", ".join(perm)}>>>" for perm in permutations]
62-
valid_value = "{{\"1\", {2, {3, {4, 5}}}}}"
73+
valid_types = [
74+
f"std::map<std::string, std::vector<std::variant<{", ".join(perm)}>>>"
75+
for perm in permutations
76+
]
77+
valid_value = '{{"1", {2, {3, {4, 5}}}}}'
6378
valid_results = [f"{tp1} test = {valid_value}" for tp1 in valid_types]
6479

6580
assert result in valid_results
6681

82+
6783
def test_cpp_static_functions(tmp_path: Path, pytestconfig: pytest.Config):
6884
cpp = LANGUAGES["cpp"](pytestconfig)
6985
object_function = "foo.bar()"
@@ -81,6 +97,7 @@ def test_cpp_static_functions(tmp_path: Path, pytestconfig: pytest.Config):
8197

8298
assert result == "(foo()).bar()"
8399

100+
84101
def test_cpp_unknown_return_type_without_streamable_is_null(
85102
tmp_path: Path, pytestconfig: pytest.Config
86103
):
@@ -96,7 +113,7 @@ def test_cpp_unknown_return_type_without_streamable_is_null(
96113
updates = assert_valid_output(result, pytestconfig)
97114
assert updates.find_status_enum() == ["wrong"]
98115
received_data = updates.find_next("close-test")["generated"]
99-
assert received_data == 'None'
116+
assert received_data == "None"
100117

101118

102119
def test_typescript_array_typing(tmp_path: Path, pytestconfig: pytest.Config):

tests/test_parallel_execution.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@ def test_parallel_isbn(lang: str, tmp_path: Path, pytestconfig: pytest.Config):
2424

2525
@pytest.mark.parametrize(
2626
"lang",
27-
[
28-
"java",
29-
"python",
30-
"kotlin",
31-
"haskell",
32-
"runhaskell",
33-
"cpp"
34-
],
27+
["java", "python", "kotlin", "haskell", "runhaskell", "cpp"],
3528
)
3629
def test_parallel_isbn_list(lang: str, tmp_path: Path, pytestconfig: pytest.Config):
3730
config_ = {"options": {"parallel": True}}

0 commit comments

Comments
 (0)