From: Thanh Ha Date: Sun, 5 Mar 2017 04:20:39 +0000 (-0500) Subject: Add unit tests for version script X-Git-Tag: v0.0.6~1 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F65%2F4065%2F1;p=releng%2Flftools.git Add unit tests for version script Adds unit tests for the version script to ensure it works in the use cases OpenDaylight requires the script for. Unit Tests run against Python 3 as we are only supporting Python 3 for lftools at the moment. - Fix version script not running 'release' command - Add pytest - Test version script for 3 use cases: 1) Version bump for release 2) Version bump by x.y.(z+1) post release 3) Version bump by x.(y+1).z Change-Id: Ib36d9a84e2769863083400c434e1539b302869a8 Signed-off-by: Thanh Ha --- diff --git a/.gitignore b/.gitignore index d366ccc4..5666024d 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ target/ .project # Python +.cache/ +.eggs/ .tox/ __pycache__/ *.egg-info/ diff --git a/setup.py b/setup.py index 4f225a05..04bc90f1 100644 --- a/setup.py +++ b/setup.py @@ -32,6 +32,8 @@ setup( 'tests.*', 'tests' ]), + setup_requires=['pytest-runner'], + tests_require=['pytest'], entry_points=''' [console_scripts] lftools=lftools.cli:cli diff --git a/shell/version b/shell/version index f17a73cc..12a74995 100755 --- a/shell/version +++ b/shell/version @@ -59,6 +59,7 @@ version() { release ) RELEASE_TAG=$1 echo "Bumping SNAPSHOTS to $RELEASE_TAG" + version_release exit 0 ;; * ) diff --git a/tests/fixtures/pom.xml b/tests/fixtures/pom.xml new file mode 100644 index 00000000..0b4d73d5 --- /dev/null +++ b/tests/fixtures/pom.xml @@ -0,0 +1,8 @@ + + + 4.0.0 + org.linuxfoundation.releng + test-artifact + 1.0.0-SNAPSHOT + diff --git a/tests/fixtures/pom.xml.expected-bump b/tests/fixtures/pom.xml.expected-bump new file mode 100644 index 00000000..337f387e --- /dev/null +++ b/tests/fixtures/pom.xml.expected-bump @@ -0,0 +1,8 @@ + + + 4.0.0 + org.linuxfoundation.releng + test-artifact + 1.1.0-SNAPSHOT + diff --git a/tests/fixtures/pom.xml.expected-release b/tests/fixtures/pom.xml.expected-release new file mode 100644 index 00000000..f8769e37 --- /dev/null +++ b/tests/fixtures/pom.xml.expected-release @@ -0,0 +1,8 @@ + + + 4.0.0 + org.linuxfoundation.releng + test-artifact + 1.0.0-TestRelease + diff --git a/tests/fixtures/pom.xml.expected-release-bump b/tests/fixtures/pom.xml.expected-release-bump new file mode 100644 index 00000000..24b6ae39 --- /dev/null +++ b/tests/fixtures/pom.xml.expected-release-bump @@ -0,0 +1,8 @@ + + + 4.0.0 + org.linuxfoundation.releng + test-artifact + 1.0.1-SNAPSHOT + diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 00000000..9d8fe847 --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,44 @@ +import difflib +from distutils import dir_util +import filecmp +import os + +import click +import pytest + +from lftools import cli + + +FIXTURE_DIR = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + 'fixtures', + ) + + +@pytest.mark.datafiles( + os.path.join(FIXTURE_DIR, 'pom.xml'), + os.path.join(FIXTURE_DIR, 'pom.xml.expected-bump'), + ) +def test_version_bump(cli_runner, datafiles): + os.chdir(datafiles) + + # Version bump should bump versions by x.(y+1).z + result = cli_runner.invoke(cli.cli, ['version', 'bump', 'TestRelease']) + assert filecmp.cmp('pom.xml', 'pom.xml.expected-bump') + + +@pytest.mark.datafiles( + os.path.join(FIXTURE_DIR, 'pom.xml'), + os.path.join(FIXTURE_DIR, 'pom.xml.expected-release'), + os.path.join(FIXTURE_DIR, 'pom.xml.expected-release-bump'), + ) +def test_version_release(cli_runner, datafiles): + os.chdir(datafiles) + + # Version release should modify SNAPSHOT to TestRelease + result = cli_runner.invoke(cli.cli, ['version', 'release', 'TestRelease']) + assert filecmp.cmp('pom.xml', 'pom.xml.expected-release') + + # Post release bump should bump versions by x.y.(z+1) and revert back to SNAPSHOT + result = cli_runner.invoke(cli.cli, ['version', 'bump', 'TestRelease']) + assert filecmp.cmp('pom.xml', 'pom.xml.expected-release-bump') diff --git a/tox.ini b/tox.ini index 974a81a2..e2fb3903 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,16 @@ minversion = 1.6 envlist = coala, docs, - docs-linkcheck + docs-linkcheck, + py3 + +[testenv] +deps = + -r{toxinidir}/requirements.txt + pytest + pytest-click + pytest-datafiles +commands = pytest [testenv:coala] basepython = python3