forked from openapi-generators/openapi-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_utils.py
More file actions
82 lines (57 loc) · 2.44 KB
/
test_utils.py
File metadata and controls
82 lines (57 loc) · 2.44 KB
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
import pytest
from openapi_python_client import utils
def test_snake_case_uppercase_str():
assert utils.snake_case("HTTP") == "http"
assert utils.snake_case("HTTP RESPONSE") == "http_response"
def test_snake_case_from_pascal_with_acronyms():
assert utils.snake_case("HTTPResponse") == "http_response"
assert utils.snake_case("APIClientHTTPResponse") == "api_client_http_response"
assert utils.snake_case("OAuthClientHTTPResponse") == "o_auth_client_http_response"
assert utils.snake_case("S3Config") == "s3_config"
def test_snake_case_from_pascal_with_numbers():
assert utils.snake_case("Response200") == "response_200"
assert utils.snake_case("Response200WithContent") == "response_200_with_content"
def test_snake_case_from_pascal():
assert utils.snake_case("HttpResponsePascalCase") == "http_response_pascal_case"
def test_snake_case_from_camel():
assert utils.snake_case("httpResponseLowerCamel") == "http_response_lower_camel"
assert utils.snake_case("connectionID") == "connection_id"
def test_kebab_case():
assert utils.kebab_case("keep_alive") == "keep-alive"
def test__sanitize():
assert utils.sanitize("something*~with lots_- of weird things}=") == "somethingwith lots_- of weird things"
def test_no_string_escapes():
assert utils.remove_string_escapes('an "evil" string') == 'an \\"evil\\" string'
def test__fix_keywords():
assert utils.fix_keywords("None") == "None_"
@pytest.mark.parametrize(
"reserved_word, expected",
[
("self", "self_"),
("int", "int_"),
("dict", "dict_"),
("not_reserved", "not_reserved"),
("type", "type"),
("id", "id"),
],
)
def test__fix_reserved_words(reserved_word: str, expected: str):
assert utils.fix_reserved_words(reserved_word) == expected
def test_to_valid_python_identifier():
assert utils.to_valid_python_identifier("valid") == "valid"
assert utils.to_valid_python_identifier("1") == "field_1"
assert utils.to_valid_python_identifier("$") == "field_"
assert utils.to_valid_python_identifier("for") == "for_"
@pytest.mark.parametrize(
"before, after",
[
("PascalCase", "PascalCase"),
("snake_case", "SnakeCase"),
("TLAClass", "TLAClass"),
("Title Case", "TitleCase"),
("s3_config", "S3Config"),
("__LeadingUnderscore", "LeadingUnderscore"),
],
)
def test_pascalcase(before, after):
assert utils.pascal_case(before) == after