forked from Azure/azure-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic script to get command coverage (Azure#245)
Basic script to get command coverage
- Loading branch information
1 parent
7a436af
commit 3579d8b
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,6 @@ src/build | |
|
||
# Azure deployment credentials | ||
*.pubxml | ||
|
||
# Auxiliary files | ||
command_coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from __future__ import print_function | ||
import os | ||
import sys | ||
from subprocess import check_call, CalledProcessError | ||
import azure.cli.application as application | ||
|
||
COVERAGE_FILE = 'command_coverage.txt' | ||
DEVNULL = open(os.devnull, 'w') | ||
|
||
config = application.Configuration([]) | ||
application.APPLICATION = application.Application(config) | ||
cmd_table = config.get_command_table() | ||
cmd_list = [x['name'].strip() for x in cmd_table.values()] | ||
cmd_set = set(cmd_list) | ||
if os.path.isfile(COVERAGE_FILE): | ||
os.remove(COVERAGE_FILE) | ||
|
||
print('Running tests...') | ||
try: | ||
check_call(['python', 'scripts/command_modules/test.py'], stdout=DEVNULL, stderr=DEVNULL, | ||
env=dict(os.environ, AZURE_CLI_TEST_TRACK_COMMANDS='1')) | ||
except CalledProcessError as err: | ||
print(err, file=sys.stderr) | ||
print("Tests failed.") | ||
sys.exit(1) | ||
print('Tests passed.') | ||
|
||
commands_tested_with_params = [line.rstrip('\n') for line in open(COVERAGE_FILE)] | ||
|
||
commands_tested = [] | ||
for tested_command in commands_tested_with_params: | ||
for c in cmd_list: | ||
if tested_command.startswith(c): | ||
commands_tested.append(c) | ||
|
||
commands_tested_set = set(commands_tested) | ||
untested = list(cmd_set - commands_tested_set) | ||
print() | ||
print("Untested commands") | ||
print("=================") | ||
print('\n'.join(sorted(untested))) | ||
percentage_tested = (len(commands_tested_set) / len(cmd_set)) * 100 | ||
print() | ||
print('Total commands {}, Tested commands {}, Untested commands {}'.format( | ||
len(cmd_set), | ||
len(commands_tested_set), | ||
len(cmd_set)-len(commands_tested_set))) | ||
print('COMMAND COVERAGE {0:.2f}%'.format(percentage_tested)) | ||
|
||
# Delete the command coverage file | ||
if os.path.isfile(COVERAGE_FILE): | ||
os.remove(COVERAGE_FILE) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters