28
28
import docutils .parsers .rst
29
29
import docutils .utils
30
30
31
+ import pytest
32
+
31
33
from awscli .argparser import MainArgParser
32
34
from awscli .argparser import ServiceArgParser
33
35
from awscli .testutils import BaseAWSHelpOutputTest , create_clidriver
@@ -66,13 +68,45 @@ def noop_test(self):
66
68
pass
67
69
68
70
69
- def test_examples ():
71
+ def _get_example_test_cases ():
72
+ test_cases = []
70
73
for command , subcommands in COMMAND_EXAMPLES .items ():
71
74
for subcommand in subcommands :
72
- yield verify_has_examples , command , subcommand
75
+ test_cases .append ((command , subcommand ))
76
+ return test_cases
77
+
78
+
79
+ def _get_all_doc_examples ():
80
+ rst_doc_examples = []
81
+ other_doc_examples = []
82
+ # Iterate over all rst doc examples0
83
+ for root , _ , filenames in os .walk (EXAMPLES_DIR ):
84
+ for filename in filenames :
85
+ full_path = os .path .join (root , filename )
86
+ if not filename .endswith ('.rst' ):
87
+ other_doc_examples .append (full_path )
88
+ continue
89
+ rst_doc_examples .append (full_path )
90
+ return rst_doc_examples , other_doc_examples
91
+
92
+
93
+ RST_DOC_EXAMPLES , OTHER_DOC_EXAMPLES = _get_all_doc_examples ()
94
+ EXAMPLE_COMMAND_TESTS = _get_example_test_cases ()
95
+
96
+
97
+ @pytest .fixture (scope = "module" )
98
+ def command_validator ():
99
+ # CLIDriver can take up a lot of resources so we'll just create one
100
+ # instance and use it for all the validation tests.
101
+ driver = create_clidriver ()
102
+ return CommandValidator (driver )
73
103
74
104
75
- def verify_has_examples (command , subcommand ):
105
+ @pytest .mark .parametrize (
106
+ "command, subcommand" ,
107
+ EXAMPLE_COMMAND_TESTS
108
+ )
109
+ def test_examples (command , subcommand ):
76
110
t = _ExampleTests (methodName = 'noop_test' )
77
111
t .setUp ()
78
112
try :
@@ -82,27 +116,14 @@ def verify_has_examples(command, subcommand):
82
116
t .tearDown ()
83
117
84
118
85
- def test_all_doc_examples ():
86
- # CLIDriver can take up a lot of resources so we'll just create one
87
- # instance and use it for all the validation tests.
88
- driver = create_clidriver ()
89
- command_validator = CommandValidator (driver )
90
-
91
- for example_file in iter_all_doc_examples ():
92
- yield verify_has_only_ascii_chars , example_file
93
- yield verify_is_valid_rst , example_file
94
- yield verify_cli_commands_valid , example_file , command_validator
95
-
96
-
97
- def iter_all_doc_examples ():
98
- # Iterate over all rst doc examples0
99
- _dname = os .path .dirname
100
- for rootdir , _ , filenames in os .walk (EXAMPLES_DIR ):
101
- for filename in filenames :
102
- if not filename .endswith ('.rst' ):
103
- continue
104
- full_path = os .path .join (rootdir , filename )
105
- yield full_path
119
+ @pytest .mark .parametrize (
120
+ "example_file" ,
121
+ RST_DOC_EXAMPLES
122
+ )
123
+ def test_rst_doc_examples (command_validator , example_file ):
124
+ verify_has_only_ascii_chars (example_file )
125
+ verify_is_valid_rst (example_file )
126
+ verify_cli_commands_valid (example_file , command_validator )
106
127
107
128
108
129
def verify_has_only_ascii_chars (filename ):
@@ -263,12 +284,14 @@ def default_visit(self, node):
263
284
pass
264
285
265
286
266
- def test_example_file_names ():
267
- for root , _ , files in os .walk (EXAMPLES_DIR ):
268
- for filename in files :
269
- filepath = os .path .join (root , filename )
270
- yield (_assert_file_is_rst_or_txt , filepath )
271
- yield (_assert_name_contains_only_allowed_characters , filename )
287
+ @pytest .mark .parametrize (
288
+ "example_file" ,
289
+ RST_DOC_EXAMPLES + OTHER_DOC_EXAMPLES
290
+ )
291
+ def test_example_file_name (example_file ):
292
+ filename = example_file .split (os .sep )[- 1 ]
293
+ _assert_file_is_rst_or_txt (example_file )
294
+ _assert_name_contains_only_allowed_characters (filename )
272
295
273
296
274
297
def _assert_file_is_rst_or_txt (filepath ):
0 commit comments