Skip to content

Commit

Permalink
"run_tests" script enhancements (Azure#5468)
Browse files Browse the repository at this point in the history
* Test script enhancements.

* Code review feedback

* Update travis.yml file.

* Update .travis.yml config.
  • Loading branch information
tjprescott authored Feb 6, 2018
1 parent 69e454a commit 755597c
Show file tree
Hide file tree
Showing 36 changed files with 3,363 additions and 3,047 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
python: 3.6
- stage: verify
env: PURPOSE='Automation'
script: ./scripts/ci/test_automation.sh
script: travis_wait 30 ./scripts/ci/test_automation.sh
python: 3.6
- stage: verify
env: PURPOSE='Automation'
script: ./scripts/ci/test_automation.sh
script: travis_wait 30 ./scripts/ci/test_automation.sh
python: 2.7
- stage: verify
script: ./scripts/ci/test_static.sh
Expand Down
10 changes: 5 additions & 5 deletions azure-cli2017.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<Compile Include="azure-cli-core\azure\cli\core\tests\test_storage_validators.py" />
<Compile Include="azure-cli-core\azure\cli\core\tests\test_telemetry.py" />
<Compile Include="azure-cli-core\azure\cli\core\tests\test_util.py" />
<Compile Include="azure-cli-core\azure\cli\core\tests\test_validators.py" />
<Compile Include="azure-cli-core\azure\cli\core\tests\test_core_validators.py" />
<Compile Include="azure-cli-core\azure\cli\core\util.py" />
<Compile Include="azure-cli-core\azure\cli\core\_config.py" />
<Compile Include="azure-cli-core\azure\cli\core\_debug.py" />
Expand Down Expand Up @@ -395,7 +395,7 @@
<Compile Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\commands.py" />
<Compile Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\custom.py" />
<Compile Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\tests\latest\test_lab.py" />
<Compile Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\tests\latest\test_validators.py" />
<Compile Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\tests\latest\test_lab_validators.py" />
<Compile Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\validators.py" />
<Compile Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\_client_factory.py" />
<Compile Include="command_modules\azure-cli-lab\azure\cli\command_modules\lab\_format.py" />
Expand Down Expand Up @@ -448,7 +448,7 @@
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\_template_builder.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\_util.py" />
<Compile Include="command_modules\azure-cli-network\azure\cli\command_modules\network\_validators.py" />
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\tests\latest\test_custom.py" />
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\tests\latest\test_profile_custom.py" />
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\_completers.py" />
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\_format.py" />
<Compile Include="command_modules\azure-cli-profile\azure\cli\command_modules\profile\_help.py">
Expand Down Expand Up @@ -488,7 +488,7 @@
<Compile Include="command_modules\azure-cli-reservations\azure_bdist_wheel.py" />
<Compile Include="command_modules\azure-cli-reservations\setup.py" />
<Compile Include="command_modules\azure-cli-resource\azure\cli\command_modules\resource\tests\latest\test_api_check.py" />
<Compile Include="command_modules\azure-cli-resource\azure\cli\command_modules\resource\tests\latest\test_custom.py" />
<Compile Include="command_modules\azure-cli-resource\azure\cli\command_modules\resource\tests\latest\test_resource_custom.py" />
<Compile Include="command_modules\azure-cli-resource\azure\cli\command_modules\resource\tests\latest\test_locks.py" />
<Compile Include="command_modules\azure-cli-resource\azure\cli\command_modules\resource\tests\latest\test_resource.py" />
<Compile Include="command_modules\azure-cli-resource\azure\cli\command_modules\resource\tests\latest\test_resource_id_deletes.py" />
Expand All @@ -502,7 +502,7 @@
<Compile Include="command_modules\azure-cli-resource\azure\cli\command_modules\resource\_params.py" />
<Compile Include="command_modules\azure-cli-role\azure\cli\command_modules\role\custom.py" />
<Compile Include="command_modules\azure-cli-role\azure\cli\command_modules\role\tests\latest\role_scenario_test.py" />
<Compile Include="command_modules\azure-cli-role\azure\cli\command_modules\role\tests\latest\test_custom.py" />
<Compile Include="command_modules\azure-cli-role\azure\cli\command_modules\role\tests\latest\test_role_custom.py" />
<Compile Include="command_modules\azure-cli-role\azure\cli\command_modules\role\tests\latest\test_graph.py" />
<Compile Include="command_modules\azure-cli-role\azure\cli\command_modules\role\tests\latest\test_role.py" />
<Compile Include="command_modules\azure-cli-role\azure\cli\command_modules\role\tests\latest\test_role_commands_thru_mock.py" />
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/test_automation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ title "Switch profile to $target_profile"

az cloud set -n AzureCloud --profile $target_profile

title 'Runing tests'
coverage run -m automation test --parallel --ci
title 'Running tests'
coverage run -m automation test --ci
coverage combine
codecov
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class GenericUpdateTest(unittest.TestCase):
def setUpClass(cls):
logging.getLogger().setLevel(logging.ERROR)

def test_generic_update(self): # pylint: disable=too-many-statements
def test_generic_update_scenario(self): # pylint: disable=too-many-statements

my_obj, loader_cls = _prepare_test_loader()
cli = TestCli(commands_loader_cls=loader_cls)
Expand Down
28 changes: 8 additions & 20 deletions src/azure-cli-testsdk/azure/cli/testsdk/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# --------------------------------------------------------------------------------------------

import os
import subprocess
import json
import shlex
import logging
Expand Down Expand Up @@ -164,26 +163,23 @@ def get_subscription_id(self):


class ExecutionResult(object):
def __init__(self, cli_ctx, command, expect_failure=False, in_process=True):
def __init__(self, cli_ctx, command, expect_failure=False):
self.output = ''
self.applog = ''
self.command_coverage = {}

if in_process:
self._in_process_execute(cli_ctx, command, expect_failure=expect_failure)
else:
self._out_of_process_execute(command)
self._in_process_execute(cli_ctx, command, expect_failure=expect_failure)

log_val = ('Logging ' + self.applog) if self.applog else ''
if expect_failure and self.exit_code == 0:
logger.error('Command "%s" => %d. (It did not fail as expected) Output: %s. %s', command,
self.exit_code, self.output, ('Logging ' + self.applog) if self.applog else '')
logger.error('Command "%s" => %d. (It did not fail as expected). %s\n', command,
self.exit_code, log_val)
raise AssertionError('The command did not fail as it was expected.')
elif not expect_failure and self.exit_code != 0:
logger.error('Command "%s" => %d. Output: %s. %s', command, self.exit_code, self.output,
('Logging ' + self.applog) if self.applog else '')
logger.error('Command "%s" => %d. %s\n', command, self.exit_code, log_val)
raise AssertionError('The command failed. Exit code: {}'.format(self.exit_code))

logger.info('Command "%s" => %d. Output: %s. %s', command, self.exit_code, self.output,
('Logging ' + self.applog) if self.applog else '')
logger.info('Command "%s" => %d. %s\n', command, self.exit_code, log_val)

self.json_value = None
self.skip_assert = os.environ.get(ENV_SKIP_ASSERT, None) == 'True'
Expand Down Expand Up @@ -246,13 +242,5 @@ def _in_process_execute(self, cli_ctx, command, expect_failure=False):
stdout_buf.close()
logging_buf.close()

def _out_of_process_execute(self, command):
try:
self.output = subprocess.check_output(shlex.split(command)).decode('utf-8')
self.exit_code = 0
except subprocess.CalledProcessError as error:
self.exit_code, self.output = error.returncode, error.output.decode('utf-8')
self.process_error = error


execute = ExecutionResult
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from azure.cli.testsdk import TestCli


class AcrCommandsTests(unittest.TestCase):
class AcrMockCommandsTests(unittest.TestCase):

@mock.patch('azure.cli.command_modules.acr.repository.get_access_credentials', autospec=True)
@mock.patch('requests.get', autospec=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class TestMonitorDiagnosticSettings(ScenarioTest):
@ResourceGroupPreparer(location='southcentralus')
@StorageAccountPreparer(location='southcentralus')
def test_monitor_diagnostic_settings(self, resource_group, storage_account):
def test_monitor_diagnostic_settings_scenario(self, resource_group, storage_account):
nsg_name = self.create_random_name(prefix='nsg', length=16)
self.cmd('network nsg create -n {} -g {}'.format(nsg_name, resource_group))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class TestMonitorMetrics(ScenarioTest):
@ResourceGroupPreparer(location='southcentralus')
@StorageAccountPreparer()
def test_monitor_metrics(self, resource_group, storage_account):
def test_monitor_metrics_scenario(self, resource_group, storage_account):
resource_id = self.cmd(
'az storage account show -n {} -g {} --query id -otsv'.format(storage_account, resource_group)).output

Expand Down
Loading

0 comments on commit 755597c

Please sign in to comment.