Skip to content

Commit

Permalink
CI Improvements (Azure#16)
Browse files Browse the repository at this point in the history
- License check: Handle \r\n and \n
- Index check: Reject https://pypi.python.org urls
- Source tests: Install extension in its own dir before running test for extension
  • Loading branch information
derekbekoe authored Nov 4, 2017
1 parent 3485e34 commit 1a107e1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ __pycache__/
# Distribution / packaging
.Python
env/
env27/
build/
develop-eggs/
dist/
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ jobs:
env: PURPOSE='IndexVerify'
script: python ./scripts/ci/test_integration.py -v
python: 3.6
fast_finish: true
allow_failures:
- env: PURPOSE='SourceTests'
16 changes: 16 additions & 0 deletions scripts/ci/test_integration.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
Expand Down Expand Up @@ -151,6 +153,20 @@ def test_extension_url_filename(self):
self.assertEqual(os.path.basename(item['downloadUrl']), item['filename'],
"Filename must match last segment of downloadUrl")

def test_extension_url_pypi(self):
for exts in self.index['extensions'].values():
for item in exts:
url = item['downloadUrl']
pypi_url_prefix = 'https://pypi.python.org/packages/'
pythonhosted_url_prefix = 'https://files.pythonhosted.org/packages/'
if url.startswith(pypi_url_prefix):
new_url = url.replace(pypi_url_prefix, pythonhosted_url_prefix)
hash_pos = new_url.find('#')
new_url = new_url if hash_pos == -1 else new_url[:hash_pos]
self.fail("Replace {} with {}\n"
"See for more info https://wiki.archlinux.org/index.php/Python_package_guidelines"
"#PyPI_download_URLs".format(url, new_url))

def test_filename_duplicates(self):
filenames = []
for exts in self.index['extensions'].values():
Expand Down
19 changes: 17 additions & 2 deletions scripts/ci/test_source.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
#!/usr/bin/env bash
set -e
set -ex

# Install CLI & CLI testsdk
echo "Installing azure-cli-testsdk and azure-cli..."
pip install "git+https://github.com/Azure/azure-cli@dev#egg=azure-cli-testsdk&subdirectory=src/azure-cli-testsdk" -q
# TODO Update the git commit when we need a new version of azure-cli-testsdk
pip install "git+https://github.com/Azure/azure-cli@68460748e47f20cba462686c9fd20d2c720cf98c#egg=azure-cli-testsdk&subdirectory=src/azure-cli-testsdk" -q
echo "Installed."


_AZURE_EXTENSION_DIR="$AZURE_EXTENSION_DIR"

for d in src/*/azext_*/tests;
do echo "Running tests for $d";
if [ -d $d ]; then
export AZURE_EXTENSION_DIR=$(mktemp -d);
pip install --upgrade --target $AZURE_EXTENSION_DIR/ext $d/../..;
python -m unittest discover -v $d;
rm -rf $AZURE_EXTENSION_DIR;
else
echo "Skipped $d as not a directory."
fi
done;

if ! [ -z "${_AZURE_EXTENSION_DIR+_}" ] ; then
AZURE_EXTENSION_DIR="$_AZURE_EXTENSION_DIR"
export AZURE_EXTENSION_DIR
unset _AZURE_EXTENSION_DIR
fi

echo "OK. Completed tests."
2 changes: 1 addition & 1 deletion scripts/ci/verify_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def main():
file_itr = (os.path.join(current_dir, p) for p in files if p.endswith('.py'))
for python_file in file_itr:
with open(python_file, 'r') as f:
file_text = f.read()
file_text = f.read().replace('\r\n', '\n')
if file_text and (LICENSE_HEADER not in file_text and AUTOREST_LICENSE_HEADER not in file_text):
files_without_header.append(os.path.join(current_dir, python_file))

Expand Down

0 comments on commit 1a107e1

Please sign in to comment.