Skip to content

Commit 47539ef

Browse files
authored
Optimize azdev test and azdev style (#424)
* update * Update path.py * Update path.py * update * Update help.py * bug fixes * update * Update linter.py
1 parent 28159e0 commit 47539ef

5 files changed

Lines changed: 41 additions & 5 deletions

File tree

HISTORY.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
Release History
44
===============
55

6+
0.1.61
7+
++++++
8+
* `azdev test`: Add some examples.
9+
* `azdev style`: Modify the execution order of the _update_table function.
10+
* `azdev linter`: Bug fixes for `_detected_tested_command`, strictly limited to starting with test and ending with .py or .yaml
11+
612
0.1.60
713
++++++
814
* `azdev statistics list-command-table`: Handle exceptions when source code cannot be retrieved

azdev/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# license information.
55
# -----------------------------------------------------------------------------
66

7-
__VERSION__ = '0.1.60'
7+
__VERSION__ = '0.1.61'

azdev/help.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,33 @@
114114
populator-commands:
115115
- pytest -h
116116
examples:
117+
- name: Run all tests.
118+
text: azdev test
119+
120+
- name: Run tests for main modules.
121+
text: azdev test CLI
122+
123+
- name: Run tests for extensions.
124+
text: azdev test EXT
125+
117126
- name: Run tests for specific modules.
118127
text: azdev test {mod1} {mod2}
119128
129+
- name: Run tests for specific cli modules, it is recommended to use the long name azure-cli-{mod}.
130+
text: azdev test azure-cli-vm azure-cli-compute
131+
132+
- name: Run tests for specific extensions, it is recommended to use the long name azext_{ext}.
133+
text: azdev test azext_containerapp azext_aosm
134+
135+
- name: Run tests for specific test files.
136+
text: azdev test test_account_scenario
137+
138+
- name: Run tests for specific python class.
139+
text: azdev test SubscriptionClientScenarioTest
140+
141+
- name: Run tests for specific test cases.
142+
text: azdev test test_account
143+
120144
- name: Re-run the tests that failed the previous run.
121145
text: azdev test --lf
122146

azdev/operations/linter/linter.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,15 @@ def _detect_tested_command(self, diff_index):
292292
# get tested command by regex
293293
for diff in diff_index:
294294
filename = diff.a_path.split('/')[-1]
295-
if re.findall(r'test_.*.py', filename) and os.path.exists(os.path.join(get_cli_repo_path(), diff.a_path)):
295+
if re.findall(r'^test_.*\.py$', filename) and \
296+
os.path.exists(os.path.join(get_cli_repo_path(), diff.a_path)):
296297
with open(os.path.join(self.git_repo, diff.a_path), encoding='utf-8') as f:
297298
lines = f.readlines()
298299
ref = get_all_tested_commands_from_regex(lines)
299300
all_tested_command += ref
300301
# get tested command by recording file
301-
if re.findall(r'test_.*.yaml', filename) and os.path.exists(os.path.join(get_cli_repo_path(), diff.a_path)):
302+
if re.findall(r'^test_.*\.yaml$', filename) and \
303+
os.path.exists(os.path.join(get_cli_repo_path(), diff.a_path)):
302304
with open(os.path.join(self.git_repo, diff.a_path)) as f:
303305
records = yaml.load(f, Loader=yaml.Loader) or {}
304306
for record in records['interactions']:

azdev/utilities/path.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,15 @@ def _update_table(package_paths, key):
241241
table[key].pop(short_name, None)
242242
table[key][long_name] = folder
243243

244-
_update_table(modules_paths, 'mod')
245-
_update_table(core_paths, 'core')
244+
# Since include_only.remove will delete the found name
245+
# Adjust the order of _update_table to ensure that extension is updated first.
246+
# When the extension name and module name are the same
247+
# Let azdev style tests the extension instead of the main module.
246248
_update_table(ext_paths, 'ext')
247249
if include_whl_extensions:
248250
_update_table(whl_ext_paths, 'ext')
251+
_update_table(modules_paths, 'mod')
252+
_update_table(core_paths, 'core')
249253

250254
if include_only:
251255
whl_extensions = [mod for whl_ext_path in whl_ext_paths for mod in include_only if mod in whl_ext_path]

0 commit comments

Comments
 (0)