Add new tests for check-uuid tool
Create tests to check whether the --fix and --package arguments of check-uuid utility work correctly. Partially-Implements: blueprint tempest-cli-unit-test-coverage Change-Id: Iadab5b1f0e0b61de3f5686c964c691dfe8c7ecd5
This commit is contained in:
parent
a7203be653
commit
a9af3ead37
@ -11,13 +11,56 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
|
import fixtures
|
||||||
|
|
||||||
from tempest.lib.cmd import check_uuid
|
from tempest.lib.cmd import check_uuid
|
||||||
from tempest.tests import base
|
from tempest.tests import base
|
||||||
|
|
||||||
|
|
||||||
|
class TestCLInterface(base.TestCase):
|
||||||
|
CODE = "import unittest\n" \
|
||||||
|
"class TestClass(unittest.TestCase):\n" \
|
||||||
|
" def test_tests(self):\n" \
|
||||||
|
" pass"
|
||||||
|
|
||||||
|
def create_tests_file(self, directory):
|
||||||
|
with open(directory + "/__init__.py", "w"):
|
||||||
|
pass
|
||||||
|
|
||||||
|
tests_file = directory + "/tests.py"
|
||||||
|
with open(tests_file, "w") as fake_file:
|
||||||
|
fake_file.write(TestCLInterface.CODE)
|
||||||
|
|
||||||
|
return tests_file
|
||||||
|
|
||||||
|
def test_fix_argument_no(self):
|
||||||
|
temp_dir = self.useFixture(fixtures.TempDir(rootdir="."))
|
||||||
|
tests_file = self.create_tests_file(temp_dir.path)
|
||||||
|
|
||||||
|
sys.argv = [sys.argv[0]] + ["--package",
|
||||||
|
os.path.relpath(temp_dir.path)]
|
||||||
|
|
||||||
|
self.assertRaises(SystemExit, check_uuid.run)
|
||||||
|
with open(tests_file, "r") as f:
|
||||||
|
self.assertTrue(TestCLInterface.CODE == f.read())
|
||||||
|
|
||||||
|
def test_fix_argument_yes(self):
|
||||||
|
temp_dir = self.useFixture(fixtures.TempDir(rootdir="."))
|
||||||
|
tests_file = self.create_tests_file(temp_dir.path)
|
||||||
|
|
||||||
|
sys.argv = [sys.argv[0]] + ["--fix", "--package",
|
||||||
|
os.path.relpath(temp_dir.path)]
|
||||||
|
|
||||||
|
check_uuid.run()
|
||||||
|
with open(tests_file, "r") as f:
|
||||||
|
self.assertTrue(TestCLInterface.CODE != f.read())
|
||||||
|
|
||||||
|
|
||||||
class TestSourcePatcher(base.TestCase):
|
class TestSourcePatcher(base.TestCase):
|
||||||
def test_add_patch(self):
|
def test_add_patch(self):
|
||||||
patcher = check_uuid.SourcePatcher()
|
patcher = check_uuid.SourcePatcher()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user