mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Now that it's working let's make it a little nicer to use [GH-522]
This allows for tests to be written without too much change from the normal unittest workflow. Now they should use the 'saltunittest' namespace and we will need to import anything we need from the original 'unittest' or 'unittest2' namespace.
This commit is contained in:
parent
dde4198dae
commit
11cc43d22d
6 changed files with 29 additions and 57 deletions
|
@ -4,21 +4,12 @@ from os import path
|
|||
import os
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
# support python < 2.7 via unittest2
|
||||
if sys.version_info[0:2] < (2,7):
|
||||
try:
|
||||
from unittest2 import TestCase, expectedFailure
|
||||
except ImportError:
|
||||
print "You need to install unittest2 to run the salt tests"
|
||||
sys.exit(1)
|
||||
else:
|
||||
from unittest import TestCase, expectedFailure
|
||||
import saltunittest
|
||||
|
||||
TEMPLATES_DIR = path.dirname(path.abspath(__file__))
|
||||
|
||||
monkey_pathed = (list_hosts, set_host, add_host, rm_host)
|
||||
class HostsModuleTest(TestCase):
|
||||
class HostsModuleTest(saltunittest.TestCase):
|
||||
def setUp(self):
|
||||
self._hfn = [f.hosts_filename for f in monkey_pathed]
|
||||
self.files = path.join(TEMPLATES_DIR, 'files')
|
||||
|
|
|
@ -1,17 +1,7 @@
|
|||
from modules import run_module
|
||||
import sys
|
||||
import saltunittest
|
||||
|
||||
# support python < 2.7 via unittest2
|
||||
if sys.version_info[0:2] < (2,7):
|
||||
try:
|
||||
from unittest2 import TestCase, expectedFailure
|
||||
except ImportError:
|
||||
print "You need to install unittest2 to run the salt tests"
|
||||
sys.exit(1)
|
||||
else:
|
||||
from unittest import TestCase, expectedFailure
|
||||
|
||||
class TestModuleTest(TestCase):
|
||||
class TestModuleTest(saltunittest.TestCase):
|
||||
def test_ping(self):
|
||||
ret = run_module('test.ping')
|
||||
assert ret == {'return': True}
|
||||
|
|
|
@ -4,21 +4,10 @@ Discover all instances of unittest.TestCase in this directory.
|
|||
|
||||
The current working directory must be set to the build of the salt you want to test.
|
||||
'''
|
||||
from saltunittest import TestLoader, TextTestRunner
|
||||
from os.path import dirname, abspath, relpath, splitext, normpath
|
||||
import sys, os, fnmatch
|
||||
|
||||
# Since all the salt tests are written under python 2.7 they take
|
||||
# advantage of all the new functionality that was added in that
|
||||
# version. We need to use the unittest2 module on python < 2.7
|
||||
if sys.version_info[0:2] < (2,7):
|
||||
try:
|
||||
from unittest2 import TestLoader, TextTestRunner
|
||||
except ImportError:
|
||||
print "You need to install unittest2 to run the salt tests"
|
||||
sys.exit(1)
|
||||
else:
|
||||
from unittest import TestLoader, TextTestRunner
|
||||
|
||||
TEST_DIR = dirname(normpath(abspath(__file__)))
|
||||
SALT_BUILD = os.getcwd()
|
||||
TEST_FILES = '*.py'
|
||||
|
|
22
tests/saltunittest.py
Normal file
22
tests/saltunittest.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
"""
|
||||
This file provides a single interface to unittest objects for our
|
||||
tests while supporting python < 2.7 via unittest2.
|
||||
|
||||
If you need something from the unittest namespace it should be
|
||||
imported here from the relevant module and then imported into your
|
||||
test from here
|
||||
"""
|
||||
|
||||
import sys
|
||||
|
||||
# support python < 2.7 via unittest2
|
||||
if sys.version_info[0:2] < (2,7):
|
||||
try:
|
||||
from unittest2 import TestLoader, TextTestRunner,\
|
||||
TestCase, expectedFailure
|
||||
except ImportError:
|
||||
print "You need to install unittest2 to run the salt tests"
|
||||
sys.exit(1)
|
||||
else:
|
||||
from unittest import TestLoader, TextTestRunner,\
|
||||
TestCase, expectedFailure
|
|
@ -1,14 +1,4 @@
|
|||
import sys
|
||||
|
||||
# support python < 2.7 via unittest2
|
||||
if sys.version_info[0:2] < (2,7):
|
||||
try:
|
||||
from unittest2 import TestCase, expectedFailure
|
||||
except ImportError:
|
||||
print "You need to install unittest2 to run the salt tests"
|
||||
sys.exit(1)
|
||||
else:
|
||||
from unittest import TestCase, expectedFailure
|
||||
from saltunittest import TestCase, expectedFailure
|
||||
|
||||
class SimpleTest(TestCase):
|
||||
def test_success(self):
|
||||
|
|
|
@ -2,17 +2,7 @@ from os import path
|
|||
from salt.utils.jinja import SaltCacheLoader, get_template
|
||||
from jinja2 import Environment
|
||||
|
||||
import sys
|
||||
|
||||
# support python < 2.7 via unittest2
|
||||
if sys.version_info[0:2] < (2,7):
|
||||
try:
|
||||
from unittest2 import TestCase, expectedFailure
|
||||
except ImportError:
|
||||
print "You need to install unittest2 to run the salt tests"
|
||||
sys.exit(1)
|
||||
else:
|
||||
from unittest import TestCase, expectedFailure
|
||||
from saltunittest import TestCase
|
||||
|
||||
TEMPLATES_DIR = path.dirname(path.abspath(__file__))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue