Optimize azdev test and azdev style (#424)

* update

* Update path.py

* Update path.py

* update

* Update help.py

* bug fixes

* update

* Update linter.py
This commit is contained in:
ZelinWang 2023-12-04 16:04:19 +08:00 коммит произвёл GitHub
Родитель 28159e054f
Коммит 47539ef4fc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 41 добавлений и 5 удалений

Просмотреть файл

@ -3,6 +3,12 @@
Release History
===============
0.1.61
++++++
* `azdev test`: Add some examples.
* `azdev style`: Modify the execution order of the _update_table function.
* `azdev linter`: Bug fixes for `_detected_tested_command`, strictly limited to starting with test and ending with .py or .yaml
0.1.60
++++++
* `azdev statistics list-command-table`: Handle exceptions when source code cannot be retrieved

Просмотреть файл

@ -4,4 +4,4 @@
# license information.
# -----------------------------------------------------------------------------
__VERSION__ = '0.1.60'
__VERSION__ = '0.1.61'

Просмотреть файл

@ -114,9 +114,33 @@ helps['test'] = """
populator-commands:
- pytest -h
examples:
- name: Run all tests.
text: azdev test
- name: Run tests for main modules.
text: azdev test CLI
- name: Run tests for extensions.
text: azdev test EXT
- name: Run tests for specific modules.
text: azdev test {mod1} {mod2}
- name: Run tests for specific cli modules, it is recommended to use the long name azure-cli-{mod}.
text: azdev test azure-cli-vm azure-cli-compute
- name: Run tests for specific extensions, it is recommended to use the long name azext_{ext}.
text: azdev test azext_containerapp azext_aosm
- name: Run tests for specific test files.
text: azdev test test_account_scenario
- name: Run tests for specific python class.
text: azdev test SubscriptionClientScenarioTest
- name: Run tests for specific test cases.
text: azdev test test_account
- name: Re-run the tests that failed the previous run.
text: azdev test --lf

Просмотреть файл

@ -292,13 +292,15 @@ class Linter: # pylint: disable=too-many-public-methods, too-many-instance-attr
# get tested command by regex
for diff in diff_index:
filename = diff.a_path.split('/')[-1]
if re.findall(r'test_.*.py', filename) and os.path.exists(os.path.join(get_cli_repo_path(), diff.a_path)):
if re.findall(r'^test_.*\.py$', filename) and \
os.path.exists(os.path.join(get_cli_repo_path(), diff.a_path)):
with open(os.path.join(self.git_repo, diff.a_path), encoding='utf-8') as f:
lines = f.readlines()
ref = get_all_tested_commands_from_regex(lines)
all_tested_command += ref
# get tested command by recording file
if re.findall(r'test_.*.yaml', filename) and os.path.exists(os.path.join(get_cli_repo_path(), diff.a_path)):
if re.findall(r'^test_.*\.yaml$', filename) and \
os.path.exists(os.path.join(get_cli_repo_path(), diff.a_path)):
with open(os.path.join(self.git_repo, diff.a_path)) as f:
records = yaml.load(f, Loader=yaml.Loader) or {}
for record in records['interactions']:

Просмотреть файл

@ -241,11 +241,15 @@ def get_path_table(include_only=None, include_whl_extensions=False):
table[key].pop(short_name, None)
table[key][long_name] = folder
_update_table(modules_paths, 'mod')
_update_table(core_paths, 'core')
# Since include_only.remove will delete the found name
# Adjust the order of _update_table to ensure that extension is updated first.
# When the extension name and module name are the same
# Let azdev style tests the extension instead of the main module.
_update_table(ext_paths, 'ext')
if include_whl_extensions:
_update_table(whl_ext_paths, 'ext')
_update_table(modules_paths, 'mod')
_update_table(core_paths, 'core')
if include_only:
whl_extensions = [mod for whl_ext_path in whl_ext_paths for mod in include_only if mod in whl_ext_path]