Modify scripts to use helper module

This commit is contained in:
Derek Bekoe 2016-03-30 16:30:28 -07:00
Родитель 05ebbdfdc5
Коммит 3e18b94c49
8 изменённых файлов: 104 добавлений и 138 удалений

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

@ -7,11 +7,11 @@ python:
install:
- pip install -r requirements.txt
- pip install -e . # Install the CLI as a package
- python scripts/install_command_modules.py # Install the command modules as packages
- python scripts/command_modules/install.py # Install the command modules as packages
script:
- export PYTHONPATH=$PATHONPATH:./src
- python -m azure.cli
- pylint -r n src/azure
- python scripts/pylint_command_modules.py
- python scripts/command_modules/pylint.py
- python -m unittest discover -s src/azure/cli/tests --buffer
- python scripts/test_command_modules.py
- python scripts/command_modules/test.py

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

@ -0,0 +1,38 @@
from __future__ import print_function
import os
import sys
from subprocess import check_call, CalledProcessError
COMMAND_MODULE_PREFIX = 'azure-cli-'
def get_all_command_modules():
# The prefix for the command module folders
PATH_TO_COMMAND_MODULES = os.path.abspath(os.path.join(os.path.abspath(__file__), '..', '..', '..', 'src' , 'command_modules'))
all_command_modules = [(name, os.path.join(PATH_TO_COMMAND_MODULES, name))
for name in os.listdir(PATH_TO_COMMAND_MODULES)
if name.startswith(COMMAND_MODULE_PREFIX) and os.path.isdir(os.path.join(PATH_TO_COMMAND_MODULES, name))]
print(str(len(all_command_modules))+" command module(s) found...")
print([name for name, fullpath in all_command_modules])
return all_command_modules
def exec_command(command, stdout=None):
'''Returns True in the command was executed successfully'''
try:
print(command)
check_call(command, stdout=stdout, shell=True)
return True
except CalledProcessError as err:
print(err, file=sys.stderr)
return False
def print_summary(failed_modules):
print()
print("SUMMARY")
print("-------")
if failed_modules:
print(str(len(failed_modules))+" module(s) FAILED...", file=sys.stderr)
print("Failed modules: " + ', '.join(failed_modules), file=sys.stderr)
sys.exit(1)
else:
print("OK")

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

@ -0,0 +1,18 @@
## Install the command modules using pip ##
from __future__ import print_function
import os
from _common import get_all_command_modules, exec_command, print_summary
dev_null_file = open(os.devnull, 'w')
all_command_modules = get_all_command_modules()
print("Installing each one.")
failed_module_names = []
for name, fullpath in all_command_modules:
success = exec_command("pip install -e "+fullpath, stdout=dev_null_file)
if not success:
failed_module_names.append(name)
print_summary(failed_module_names)

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

@ -0,0 +1,17 @@
## Runs pylint on the command modules ##
from __future__ import print_function
import os
from _common import get_all_command_modules, exec_command, print_summary
all_command_modules = get_all_command_modules()
print("Running pylint on each one.")
failed_module_names = []
for name, fullpath in all_command_modules:
path_to_module = os.path.join(fullpath, 'azure')
success = exec_command("pylint -r n "+path_to_module)
if not success:
failed_module_names.append(name)
print_summary(failed_module_names)

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

@ -0,0 +1,28 @@
## Run the tests for each command module ##
from __future__ import print_function
import os
import sys
dev_null_file = open(os.devnull, 'w')
from _common import get_all_command_modules, exec_command, print_summary, COMMAND_MODULE_PREFIX
all_command_modules = get_all_command_modules()
print("Running tests on each one.")
failed_module_names = []
skipped_modules = []
for name, fullpath in all_command_modules:
path_to_module = os.path.join(fullpath, 'azure', 'cli', 'command_modules', name.replace(COMMAND_MODULE_PREFIX, ''), 'tests')
if not os.path.isdir(path_to_module):
skipped_modules.append(name)
continue
print(path_to_module)
success = exec_command("python -m unittest discover -s " + path_to_module + " --buffer", stdout=dev_null_file)
if not success:
failed_module_names.append(name)
print_summary(failed_module_names)
if skipped_modules:
print("Modules skipped as no test dir found:", ', '.join(skipped_modules), file=sys.stderr)

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

@ -1,42 +0,0 @@
## Install the command modules using pip ##
from __future__ import print_function
import os
import sys
from subprocess import check_call, CalledProcessError
dev_null_file = open(os.devnull, 'w')
# The prefix for the command module folders
COMMAND_MODULE_PREFIX = 'azure-cli-'
PATH_TO_COMMAND_MODULES = os.path.abspath(os.path.join(os.path.abspath(__file__), '..', '..', 'src' , 'command_modules'))
all_command_modules = [(name, os.path.join(PATH_TO_COMMAND_MODULES, name))
for name in os.listdir(PATH_TO_COMMAND_MODULES)
if name.startswith(COMMAND_MODULE_PREFIX) and os.path.isdir(os.path.join(PATH_TO_COMMAND_MODULES, name))]
if not all_command_modules:
print("No command modules found. If there are no command modules. This file should not be loaded in .travis.yml", file=sys.stderr)
sys.exit(1)
print(str(len(all_command_modules))+" command module(s) found...")
print("Installing each one.")
failed_modules = []
for (name, fullpath) in all_command_modules:
path_to_module = os.path.join(fullpath)
try:
check_call("pip install -e "+path_to_module, stdout=dev_null_file, shell=True)
except CalledProcessError as err:
failed_modules.append((name, err))
print(err, file=sys.stderr)
print()
print("SUMMARY")
print("-------")
if failed_modules:
print(str(len(failed_modules))+" module(s) FAILED install...", file=sys.stderr)
print("Failed modules: " + ', '.join([name for (name, err) in failed_modules]), file=sys.stderr)
sys.exit(1)
else:
print('\n'.join([name for (name, fullpath) in all_command_modules]))
print("INSTALLED COMMAND MODULES OK")

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

@ -1,43 +0,0 @@
## Runs pylint on the command modules ##
from __future__ import print_function
import os
import sys
from subprocess import check_call, CalledProcessError
# The prefix for the command module folders
COMMAND_MODULE_PREFIX = 'azure-cli-'
PATH_TO_COMMAND_MODULES = os.path.abspath(os.path.join(os.path.abspath(__file__), '..', '..', 'src' , 'command_modules'))
all_command_modules = [(name, os.path.join(PATH_TO_COMMAND_MODULES, name))
for name in os.listdir(PATH_TO_COMMAND_MODULES)
if name.startswith(COMMAND_MODULE_PREFIX) and os.path.isdir(os.path.join(PATH_TO_COMMAND_MODULES, name))]
if not all_command_modules:
print("No command modules found. If there are no command modules. This file should not be loaded in .travis.yml", file=sys.stderr)
sys.exit(1)
print(str(len(all_command_modules))+" command module(s) found...")
print("Running pylint on each one.")
failed_modules = []
# It runs through all the modules
# If pylint fails on a module, we modify success to False and carry on
# so we show all errors in all modules.
for (name, fullpath) in all_command_modules:
path_to_module = os.path.join(fullpath, 'azure')
try:
check_call("pylint -r n "+path_to_module, shell=True)
except CalledProcessError as err:
failed_modules.append((name, err))
print(err, file=sys.stderr)
print()
print("SUMMARY")
print("-------")
if failed_modules:
print(str(len(failed_modules))+" module(s) FAILED pylint...", file=sys.stderr)
print("Failed modules: " + ', '.join([name for (name, err) in failed_modules]), file=sys.stderr)
sys.exit(1)
else:
print('\n'.join([name for (name, fullpath) in all_command_modules]))
print("ALL COMMAND MODULES OK")

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

@ -1,50 +0,0 @@
## Run the tests for each command module ##
from __future__ import print_function
import os
import sys
from subprocess import check_call, CalledProcessError
dev_null_file = open(os.devnull, 'w')
# The prefix for the command module folders
COMMAND_MODULE_PREFIX = 'azure-cli-'
PATH_TO_COMMAND_MODULES = os.path.abspath(os.path.join(os.path.abspath(__file__), '..', '..', 'src' , 'command_modules'))
all_command_modules = [(name, PATH_TO_COMMAND_MODULES+'/'+name)
for name in os.listdir(PATH_TO_COMMAND_MODULES)
if name.startswith(COMMAND_MODULE_PREFIX) and os.path.isdir(os.path.join(PATH_TO_COMMAND_MODULES, name))]
if not all_command_modules:
print("No command modules found. If there are no command modules. This file should not be loaded in .travis.yml", file=sys.stderr)
sys.exit(1)
print(str(len(all_command_modules))+" command module(s) found...")
print("Running tests on each one.")
failed_modules = []
skipped_modules = []
for (name, fullpath) in all_command_modules:
path_to_module = os.path.join(fullpath, 'azure', 'cli', 'command_modules', name.replace(COMMAND_MODULE_PREFIX, ''), 'tests')
if not os.path.isdir(path_to_module):
skipped_modules.append(name)
continue
try:
print(path_to_module)
check_call("python -m unittest discover -s " + path_to_module + " --buffer", stdout=dev_null_file, shell=True)
except CalledProcessError as err:
failed_modules.append((name, err))
print(err, file=sys.stderr)
print()
print("SUMMARY")
print("-------")
if skipped_modules:
print("Modules skipped as no test dir found:", ', '.join(skipped_modules), file=sys.stderr)
print()
if failed_modules:
print(str(len(failed_modules))+" module(s) FAILED tests...", file=sys.stderr)
print("Failed modules: " + ', '.join([name for (name, err) in failed_modules]), file=sys.stderr)
sys.exit(1)
else:
print('\n'.join([name for (name, fullpath) in all_command_modules]))
print("ALL COMMAND MODULES OK")