Skip to content

Commit b2225fd

Browse files
committed
Python lint errors
1 parent 4c2684d commit b2225fd

File tree

5 files changed

+88
-41
lines changed

5 files changed

+88
-41
lines changed

openapiart/generator.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ def _get_external_field_name(self, openapi_name):
704704
if external in ["String"]:
705705
external += "_"
706706
return external
707-
707+
708708
def _small_first_char(self, words):
709709
if isinstance(words, list):
710710
ret = []
@@ -732,7 +732,7 @@ def _write_openapi_object(self, ref, choice_method_name=None):
732732
if "choice" in self._get_choice_names(schema_object):
733733
slots.append("'_choice'")
734734
self._write(1, "__slots__ = (%s)" % ",".join(slots))
735-
self._write(1, "_JSON_NAME = \"%s\"" % json_name)
735+
self._write(1, '_JSON_NAME = "%s"' % json_name)
736736

737737
# write _TYPES definition
738738
# TODO: this func won't detect whether $ref for a given property is
@@ -1081,7 +1081,11 @@ def _write_openapilist_special_methods(
10811081
self._write()
10821082
self._write(1, "def _instanceOf(self, item):")
10831083
self._write(2, "if not isinstance(item, %s):" % (contained_class_name))
1084-
self._write(3, "raise Exception(\"Item is not an instance of %s\")" % (contained_class_name))
1084+
self._write(
1085+
3,
1086+
'raise Exception("Item is not an instance of %s")'
1087+
% (contained_class_name),
1088+
)
10851089

10861090
def _write_factory_method(
10871091
self,

openapiart/openapiartgo.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,9 @@ def _build_api_interface(self):
431431
new.schema_name = self._get_schema_object_name_from_ref(
432432
ref[0].value
433433
)
434-
new.schema_raw_name = self._get_schema_json_name_from_ref(ref[0].value)
434+
new.schema_raw_name = self._get_schema_json_name_from_ref(
435+
ref[0].value
436+
)
435437
new.schema_object = self._get_schema_object_from_ref(
436438
ref[0].value
437439
)
@@ -1065,7 +1067,7 @@ def _write_interface(self, new):
10651067
}}
10661068
return str
10671069
}}
1068-
1070+
10691071
func (obj *{struct}) Clone() ({interface}, error) {{
10701072
newObj := New{interface}()
10711073
pbText, err := obj.ToPbText()
@@ -1086,7 +1088,7 @@ def _write_interface(self, new):
10861088
if len(internal_items) == 0
10871089
else "\n".join(internal_items),
10881090
nil_call="obj.setNil()" if len(internal_items_nil) > 0 else "",
1089-
obj_name=new.schema_raw_name
1091+
obj_name=new.schema_raw_name,
10901092
)
10911093
)
10921094
if len(internal_items_nil) > 0:
@@ -1782,8 +1784,12 @@ def _build_setters_getters(self, fluent_new):
17821784
if field.type == "[]byte":
17831785
field.name = "Bytes"
17841786
elif "$ref" in property_schema:
1785-
schema_name = self._get_schema_object_name_from_ref(property_schema["$ref"])
1786-
field.schema_name = self._get_schema_json_name_from_ref(property_schema["$ref"])
1787+
schema_name = self._get_schema_object_name_from_ref(
1788+
property_schema["$ref"]
1789+
)
1790+
field.schema_name = self._get_schema_json_name_from_ref(
1791+
property_schema["$ref"]
1792+
)
17871793
field.name = self._get_external_struct_name(schema_name)
17881794
field.isOptional = fluent_new.isOptional(property_name)
17891795
field.isPointer = (
@@ -1988,7 +1994,7 @@ def _validate_types(self, new, field):
19881994
validation = append(validation,
19891995
fmt.Sprintf("required field `%s.{field_name}` must not be empty", path))
19901996
}} """.format(
1991-
name=field.name, intf_name=new.schema_raw_name,
1997+
name=field.name,
19921998
field_name=field.schema_name,
19931999
value=0 if field.isEnum and field.isArray is False else value,
19942000
enum=".Number()"
@@ -2020,7 +2026,9 @@ def _validate_types(self, new, field):
20202026
).format(
20212027
name=field.schema_name,
20222028
interface=new.schema_raw_name,
2023-
max="max({})".format(field.type.lstrip("[]")) if field.max is None else field.max,
2029+
max="max({})".format(field.type.lstrip("[]"))
2030+
if field.max is None
2031+
else field.max,
20242032
pointer="*" if field.isPointer else "",
20252033
min="min({})".format(field.type.lstrip("[]"))
20262034
if field.min is None
@@ -2059,7 +2067,9 @@ def _validate_types(self, new, field):
20592067
).format(
20602068
name=field.schema_name,
20612069
interface=new.schema_name,
2062-
max_length="any" if field.max_length is None else field.max_length,
2070+
max_length="any"
2071+
if field.max_length is None
2072+
else field.max_length,
20632073
pointer="*" if field.isPointer else "",
20642074
min_length=field.min_length
20652075
if field.min_length is None
@@ -2090,11 +2100,12 @@ def _validate_types(self, new, field):
20902100
validation = append(validation, err.Error())
20912101
}}
20922102
""".format(
2093-
name=field.name, interface=new.schema_name,
2094-
field_name=field.schema_name,
2095-
format=field.format.capitalize() if field.isArray is False
2096-
else field.format.capitalize() + "Slice",
2097-
)
2103+
name=field.name,
2104+
field_name=field.schema_name,
2105+
format=field.format.capitalize()
2106+
if field.isArray is False
2107+
else field.format.capitalize() + "Slice",
2108+
)
20982109
# Enum will be handled via wrapper lib
20992110
if inner_body == "":
21002111
return body
@@ -2117,12 +2128,15 @@ def _validate_struct(self, new, field):
21172128
validation,
21182129
fmt.Sprintf("required field `%s.{field_name}` must not be empty", path))
21192130
}}
2120-
""".format(name=field.name, interface=new.schema_raw_name, field_name=field.schema_name)
2131+
""".format(
2132+
name=field.name,
2133+
field_name=field.schema_name,
2134+
)
21212135

21222136
inner_body = """obj.{external_name}().validateObj(
21232137
set_default, fmt.Sprintf("%s.{json_name}", path))""".format(
21242138
external_name=self._get_external_struct_name(field.name),
2125-
json_name=field.schema_name
2139+
json_name=field.schema_name,
21262140
)
21272141
if field.isArray:
21282142
inner_body = """
@@ -2138,8 +2152,6 @@ def _validate_struct(self, new, field):
21382152
""".format(
21392153
name=field.name,
21402154
field_name=field.schema_name,
2141-
field_type=field.type,
2142-
internal_items_name="{}Slice".format(field.struct),
21432155
field_internal_struct=field.struct,
21442156
)
21452157
body += """
@@ -2384,13 +2396,13 @@ def _write_default_method(self, new):
23842396
struct=new.struct, body=body
23852397
)
23862398
)
2387-
2399+
23882400
def _get_schema_json_name_from_ref(self, ref):
23892401
final_piece = ref.split("/")[-1]
23902402
if "." in final_piece:
23912403
return final_piece.replace(".", "_").lower()
23922404
return self._lower_first_char(final_piece)
2393-
2405+
23942406
def _lower_first_char(self, word):
23952407
return word[0].lower() + word[1:]
23962408

openapiart/tests/test_formats.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_formats_bad_string(config, value):
2020
config.l.string_param = value
2121
try:
2222
config.deserialize(config.serialize(encoding=config.YAML))
23-
pytest.fail("Value {value} was successfully validated".format(value))
23+
pytest.fail("Value {} was successfully validated".format(value))
2424
except Exception:
2525
pass
2626

@@ -50,7 +50,7 @@ def test_formats_good_ipv4(config, value):
5050
config.l.ipv4 = value
5151
try:
5252
config.deserialize(config.serialize(encoding=config.YAML))
53-
except Exception as e:
53+
except Exception:
5454
pytest.fail("Value {} was not valid".format(value))
5555

5656

openapiart/tests/test_func.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,11 @@ def test_x_pattern_integer_good_and_bad_list(default_config, integer):
139139
default_config.integer_pattern.serialize(default_config.DICT)
140140
pytest.fail("integer values got serialize")
141141
except Exception as e:
142-
if "`abcd::abcd::`" not in str(e) \
143-
or "`256`" not in str(e) or "`ab:ab:ab:ab:ab:ab`" not in str(e):
142+
if (
143+
"`abcd::abcd::`" not in str(e)
144+
or "`256`" not in str(e)
145+
or "`ab:ab:ab:ab:ab:ab`" not in str(e)
146+
):
144147
pytest.fail("Invalid integer list is not proper in error message")
145148

146149

@@ -160,7 +163,7 @@ def test_x_pattern_good_inc_dec(default_config, index, direction):
160163
dir_obj.count = count[index]
161164
try:
162165
default_config.serialize(default_config.DICT)
163-
except Exception as e:
166+
except Exception:
164167
pytest.fail("%s with %s Failed to serialize" % (enum, direction))
165168

166169

@@ -211,4 +214,3 @@ def test_enum_setter(api, default_config):
211214

212215
if __name__ == "__main__":
213216
pytest.main(["-v", "-s", __file__])
214-

openapiart/tests/test_py_go_diff.py

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import importlib
22
import pytest
3+
34
module = importlib.import_module("sanity")
45

56

@@ -31,16 +32,26 @@ def test_validation_errors():
3132
assert "required field `prefix_config.a` must not be empty" in str(e)
3233
assert "required field `prefix_config.b` must not be empty" in str(e)
3334
assert "required field `prefix_config.c` must not be empty" in str(e)
34-
assert "required field `prefix_config.required_object` must not be empty" in str(e)
35-
assert "required field `prefix_config.e.e_a` must not be empty" in str(e)
36-
assert "required field `prefix_config.e.e_b` must not be empty" in str(e)
37-
35+
assert (
36+
"required field `prefix_config.required_object` must not be empty"
37+
in str(e)
38+
)
39+
assert "required field `prefix_config.e.e_a` must not be empty" in str(
40+
e
41+
)
42+
assert "required field `prefix_config.e.e_b` must not be empty" in str(
43+
e
44+
)
45+
3846
p.e.e_a = "abc"
3947
try:
4048
p.validate()
4149
except Exception as e:
4250
print(e)
43-
assert "value of `prefix_config.e.e_a` must be a valid float type, instead of `abc`" in str(e)
51+
assert (
52+
"value of `prefix_config.e.e_a` must be a valid float type, instead of `abc`"
53+
in str(e)
54+
)
4455
p.a = "abc"
4556
p.b = 10.1
4657
p.c = 20
@@ -51,15 +62,33 @@ def test_validation_errors():
5162
p.ipv4_pattern.ipv4.value = "1.1"
5263
errors = p._validate(p._JSON_NAME, True)
5364
assert len([True for e in errors if ".e_b` must not be empty" in e]) == 2
54-
assert "required field `prefix_config.j[0].e_a` must not be empty" in errors
65+
assert (
66+
"required field `prefix_config.j[0].e_a` must not be empty" in errors
67+
)
5568
assert "required field `prefix_config.e.e_b` must not be empty" in errors
56-
assert "value of `prefix_config.e.e_a` must be a valid float type, instead of `abc`" in errors
57-
assert "required field `prefix_config.j[0].e_a` must not be empty" in errors
58-
assert "required field `prefix_config.j[0].e_b` must not be empty" in errors
59-
assert "value of `prefix_config.mac_pattern.mac.values[0]` must be a valid mac address, instead of `1`" in errors
60-
assert "value of `prefix_config.mac_pattern.mac.values[1]` must be a valid mac address, instead of `20`" in errors
61-
assert "value of `prefix_config.ipv4_pattern.ipv4.value` must be a valid ipv4 address, instead of `1.1`" in errors
62-
69+
assert (
70+
"value of `prefix_config.e.e_a` must be a valid float type, instead of `abc`"
71+
in errors
72+
)
73+
assert (
74+
"required field `prefix_config.j[0].e_a` must not be empty" in errors
75+
)
76+
assert (
77+
"required field `prefix_config.j[0].e_b` must not be empty" in errors
78+
)
79+
assert (
80+
"value of `prefix_config.mac_pattern.mac.values[0]` must be a valid mac address, instead of `1`"
81+
in errors
82+
)
83+
assert (
84+
"value of `prefix_config.mac_pattern.mac.values[1]` must be a valid mac address, instead of `20`"
85+
in errors
86+
)
87+
assert (
88+
"value of `prefix_config.ipv4_pattern.ipv4.value` must be a valid ipv4 address, instead of `1.1`"
89+
in errors
90+
)
91+
6392

6493
def test_enum_setter():
6594
p = module.Api().prefix_config()

0 commit comments

Comments
 (0)