Skip to content

Commit

Permalink
fix: azdev test cannot find core tests (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jianhui Harold authored Jan 3, 2020
1 parent 15bfa11 commit 13df704
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 9 deletions.
12 changes: 6 additions & 6 deletions azdev/operations/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ def _discover_tests(profile):

logger.info('\nCore Modules: %s', ', '.join([name for name, _ in core_modules]))
for mod_name, mod_path in core_modules:
filepath = mod_path
file_path = mod_path
for comp in mod_name.split('-'):
filepath = os.path.join(filepath, comp)
file_path = os.path.join(file_path, comp)

mod_data = {
'alt_name': 'main' if mod_name == 'azure-cli' else mod_name.replace(COMMAND_MODULE_PREFIX, ''),
'filepath': os.path.join(filepath, 'tests'),
'filepath': os.path.join(file_path, 'tests'),
'base_path': '{}.tests'.format(mod_name).replace('-', '.'),
'files': {}
}
Expand All @@ -267,14 +267,14 @@ def _discover_tests(profile):
for mod_name, mod_path in extensions:
glob_pattern = os.path.normcase(os.path.join('{}*'.format(EXTENSION_PREFIX)))
try:
filepath = glob.glob(os.path.join(mod_path, glob_pattern))[0]
file_path = glob.glob(os.path.join(mod_path, glob_pattern))[0]
except IndexError:
logger.debug("No extension found at: %s", os.path.join(mod_path, glob_pattern))
continue
import_name = os.path.basename(filepath)
import_name = os.path.basename(file_path)
mod_data = {
'alt_name': inverse_name_table[mod_name],
'filepath': os.path.join(filepath, 'tests', profile_namespace),
'filepath': os.path.join(file_path, 'tests', profile_namespace),
'base_path': '{}.tests.{}'.format(import_name, profile_namespace),
'files': {}
}
Expand Down
3 changes: 0 additions & 3 deletions azdev/utilities/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,6 @@ def _update_table(package_paths, key):
if key == 'ext':
short_name = base_name
long_name = next((item for item in os.listdir(folder) if item.startswith(EXTENSION_PREFIX)), None)
elif base_name.startswith(COMMAND_MODULE_PREFIX):
short_name = base_name.replace(COMMAND_MODULE_PREFIX, '') or '__main__'
long_name = base_name
else:
short_name = base_name
long_name = '{}{}'.format(COMMAND_MODULE_PREFIX, base_name)
Expand Down
Empty file.
52 changes: 52 additions & 0 deletions azdev/utilities/tests/test_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -----------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# -----------------------------------------------------------------------------


import unittest
import os

from azdev.utilities import get_path_table


class TestGetPathTable(unittest.TestCase):
def setUp(self):
self.path_table = get_path_table()

def test_component(self):
self.assertTrue('core' in self.path_table)
self.assertTrue('ext' in self.path_table)
self.assertTrue('mod' in self.path_table)

def test_core_modules_directory_exist(self):
if 'core' not in self.path_table:
self.skipTest("No 'core' key in what get_path_table() return")

core_modules = self.path_table['core']
for _, mod_path in core_modules.items():
self.assertTrue(os.path.isdir(mod_path))

def test_command_modules_directory_exist(self):
if 'mod' not in self.path_table:
self.skipTest("No 'mod' key in what get_path_table() return")

command_modules = self.path_table['mod']
for _, mod_path in command_modules.items():
self.assertTrue(os.path.isdir(mod_path))

def test_extension_modules_directory_exist(self):
if 'ext' not in self.path_table:
self.skipTest("No 'ext' key in what get_path_table() return")

if not self.path_table['ext']:
self.skipTest("No extension modules installed by azdev")

extension_moduels = self.path_table['ext']
for _, mod_path in extension_moduels.items():
self.assertTrue(os.path.isdir(mod_path))


if __name__ == '__main__':
unittest.main()
37 changes: 37 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,43 @@ jobs:
TargetPath: $(Build.ArtifactStagingDirectory)
ArtifactName: pypi

- job: Unittest
timeoutInMinutes: 10

pool:
vmImage: 'ubuntu-16.04'
strategy:
matrix:
Python36:
python.version: '3.6'
Python38:
python.version: '3.8'
steps:
- task: UsePythonVersion@0
displayName: 'Use Python $(python.version)'
inputs:
versionSpec: '$(python.version)'
- bash: |
set -ev
python -m venv env
. env/bin/activate
# install azdev from source code
python setup.py install
# azdev setup
git clone --quiet https://github.com/Azure/azure-cli.git
git clone --quiet https://github.com/Azure/azure-cli-extensions.git
azdev setup -c ./azure-cli -r ./azure-cli-extensions
azdev --version
# unittest
python -m unittest -v
displayName: 'Run Unittest'
- job: TestAzdevSetup
displayName: 'Test azdev setup'
dependsOn: BuildPythonWheel
Expand Down

0 comments on commit 13df704

Please sign in to comment.