7
7
8
8
import pytest
9
9
10
- from codecov import settings
10
+ from codecov import config
11
+ from codecov .exceptions import InvalidAnnotationType , MissingEnvironmentVariable
11
12
12
13
13
14
def test_path_below_existing_file ():
14
15
with tempfile .NamedTemporaryFile (suffix = '.json' ) as temp_file :
15
16
path = pathlib .Path (temp_file .name )
16
- assert settings .path_below (path ) == path .resolve ()
17
+ assert config .path_below (path ) == path .resolve ()
17
18
18
19
19
20
def test_path_below_nonexistent_file ():
20
21
path = pathlib .Path ('/path/to/nonexistent_file.json' )
21
22
with pytest .raises (ValueError ):
22
- settings .path_below (path )
23
+ config .path_below (path )
23
24
24
25
25
26
def test_path_below_directory ():
26
27
path = pathlib .Path ('/path/to/directory' )
27
28
with pytest .raises (ValueError ):
28
- settings .path_below (path )
29
+ config .path_below (path )
29
30
30
31
31
32
def test_path_below_non_json_file ():
32
33
with tempfile .NamedTemporaryFile (suffix = '.txt' ) as temp_file :
33
34
path = pathlib .Path (temp_file .name )
34
35
with pytest .raises (ValueError ):
35
- settings .path_below (path )
36
+ config .path_below (path )
36
37
37
38
38
39
def test_config_from_environ_missing ():
39
- with pytest .raises (settings . MissingEnvironmentVariable ):
40
- settings .Config .from_environ ({})
40
+ with pytest .raises (MissingEnvironmentVariable ):
41
+ config .Config .from_environ ({})
41
42
42
43
43
44
def test_config__from_environ__sample ():
44
45
token = secrets .token_urlsafe ()
45
46
with tempfile .NamedTemporaryFile (suffix = '.json' ) as temp_file :
46
- assert settings .Config .from_environ (
47
+ assert config .Config .from_environ (
47
48
{
48
49
'GITHUB_REPOSITORY' : 'your_repository' ,
49
50
'COVERAGE_PATH' : temp_file .name ,
@@ -63,7 +64,7 @@ def test_config__from_environ__sample():
63
64
'COVERAGE_REPORT_URL' : 'https://your_coverage_report_url' ,
64
65
'DEBUG' : 'False' ,
65
66
}
66
- ) == settings .Config (
67
+ ) == config .Config (
67
68
GITHUB_REPOSITORY = 'your_repository' ,
68
69
COVERAGE_PATH = pathlib .Path (temp_file .name ).resolve (),
69
70
GITHUB_TOKEN = token , # noqa: S106
@@ -87,7 +88,7 @@ def test_config__from_environ__sample():
87
88
def test_config_required_pr_or_ref ():
88
89
with tempfile .NamedTemporaryFile (suffix = '.json' ) as temp_file :
89
90
with pytest .raises (ValueError ):
90
- settings .Config .from_environ (
91
+ config .Config .from_environ (
91
92
{
92
93
'GITHUB_TOKEN' : 'your_token' ,
93
94
'GITHUB_REPOSITORY' : 'your_repository' ,
@@ -97,8 +98,8 @@ def test_config_required_pr_or_ref():
97
98
98
99
99
100
def test_config_invalid_annotation_type ():
100
- with pytest .raises (settings . InvalidAnnotationType ):
101
- settings .Config .from_environ ({'ANNOTATION_TYPE' : 'foo' })
101
+ with pytest .raises (InvalidAnnotationType ):
102
+ config .Config .from_environ ({'ANNOTATION_TYPE' : 'foo' })
102
103
103
104
104
105
@pytest .mark .parametrize (
@@ -116,78 +117,78 @@ def test_config_invalid_annotation_type():
116
117
],
117
118
)
118
119
def test_str_to_bool (input_data , output_data ):
119
- assert settings .str_to_bool (input_data ) is output_data
120
+ assert config .str_to_bool (input_data ) is output_data
120
121
121
122
122
123
def test_config_clean_minimum_green ():
123
- value = settings .Config .clean_minimum_green ('90' )
124
+ value = config .Config .clean_minimum_green ('90' )
124
125
assert value == decimal .Decimal ('90' )
125
126
126
127
127
128
def test_config_clean_minimum_orange ():
128
- value = settings .Config .clean_minimum_orange ('70' )
129
+ value = config .Config .clean_minimum_orange ('70' )
129
130
assert value == decimal .Decimal ('70' )
130
131
131
132
132
133
def test_config_clean_annotate_missing_lines ():
133
- value = settings .Config .clean_annotate_missing_lines ('True' )
134
+ value = config .Config .clean_annotate_missing_lines ('True' )
134
135
assert value is True
135
136
136
137
137
138
def test_config_clean_skip_coverage ():
138
- value = settings .Config .clean_skip_coverage ('False' )
139
+ value = config .Config .clean_skip_coverage ('False' )
139
140
assert value is False
140
141
141
142
142
143
def test_config_clean_branch_coverage ():
143
- value = settings .Config .clean_branch_coverage ('False' )
144
+ value = config .Config .clean_branch_coverage ('False' )
144
145
assert value is False
145
146
146
147
147
148
def test_config_clean_complete_project_report ():
148
- value = settings .Config .clean_complete_project_report ('True' )
149
+ value = config .Config .clean_complete_project_report ('True' )
149
150
assert value is True
150
151
151
152
152
153
def test_config_clean_debug ():
153
- value = settings .Config .clean_debug ('False' )
154
+ value = config .Config .clean_debug ('False' )
154
155
assert value is False
155
156
156
157
157
158
def test_config_clean_annotation_type ():
158
- value = settings .Config .clean_annotation_type ('warning' )
159
+ value = config .Config .clean_annotation_type ('warning' )
159
160
assert value == 'warning'
160
161
161
162
162
163
def test_config_clean_annotation_type_invalid ():
163
- with pytest .raises (settings . InvalidAnnotationType ):
164
- settings .Config .clean_annotation_type ('foo' )
164
+ with pytest .raises (InvalidAnnotationType ):
165
+ config .Config .clean_annotation_type ('foo' )
165
166
166
167
167
168
def test_config_clean_github_pr_number ():
168
- value = settings .Config .clean_github_pr_number ('123' )
169
+ value = config .Config .clean_github_pr_number ('123' )
169
170
assert value == 123
170
171
171
172
172
173
def test_config_clean_coverage_path ():
173
174
with tempfile .NamedTemporaryFile (suffix = '.json' ) as temp_file :
174
- value = settings .Config .clean_coverage_path (temp_file .name )
175
+ value = config .Config .clean_coverage_path (temp_file .name )
175
176
assert value == pathlib .Path (temp_file .name ).resolve ()
176
177
177
178
178
179
def test_config_clean_annotations_output_path ():
179
- value = settings .Config .clean_annotations_output_path ('/path/to/annotations' )
180
+ value = config .Config .clean_annotations_output_path ('/path/to/annotations' )
180
181
assert value == pathlib .Path ('/path/to/annotations' )
181
182
182
183
183
184
def test_str_to_bool_invalid ():
184
- assert settings .str_to_bool ('invalid' ) is False
185
+ assert config .str_to_bool ('invalid' ) is False
185
186
186
187
187
188
def test_config_required_clean_env_var_error ():
188
189
with tempfile .NamedTemporaryFile (suffix = '.json' ) as temp_file :
189
190
with pytest .raises (ValueError ):
190
- settings .Config .from_environ (
191
+ config .Config .from_environ (
191
192
{
192
193
'GITHUB_TOKEN' : 'your_token' ,
193
194
'GITHUB_REPOSITORY' : 'your_repository' ,
0 commit comments