mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Allow tests to be run on python < 2.7 [GH-522]
note: the host module test seems to be broken.
This commit is contained in:
parent
e075c5853c
commit
dde4198dae
5 changed files with 63 additions and 11 deletions
|
@ -1,14 +1,24 @@
|
|||
import unittest
|
||||
from salt.modules.hosts import list_hosts, get_ip, get_alias, has_pair, add_host,\
|
||||
set_host, rm_host
|
||||
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
|
||||
|
||||
TEMPLATES_DIR = path.dirname(path.abspath(__file__))
|
||||
|
||||
monkey_pathed = (list_hosts, set_host, add_host, rm_host)
|
||||
class HostsModuleTest(unittest.TestCase):
|
||||
class HostsModuleTest(TestCase):
|
||||
def setUp(self):
|
||||
self._hfn = [f.hosts_filename for f in monkey_pathed]
|
||||
self.files = path.join(TEMPLATES_DIR, 'files')
|
||||
|
|
|
@ -1,7 +1,17 @@
|
|||
import unittest
|
||||
from modules import run_module
|
||||
import sys
|
||||
|
||||
class TestModuleTest(unittest.TestCase):
|
||||
# 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):
|
||||
def test_ping(self):
|
||||
ret = run_module('test.ping')
|
||||
assert ret == {'return': True}
|
||||
|
|
|
@ -4,10 +4,21 @@ 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 unittest 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'
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
import unittest
|
||||
import sys
|
||||
|
||||
class SimpleTest(unittest.TestCase):
|
||||
# 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 SimpleTest(TestCase):
|
||||
def test_success(self):
|
||||
assert True
|
||||
@unittest.expectedFailure
|
||||
@expectedFailure
|
||||
def test_fail(self):
|
||||
assert False
|
||||
|
|
|
@ -1,8 +1,19 @@
|
|||
import unittest
|
||||
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
|
||||
|
||||
TEMPLATES_DIR = path.dirname(path.abspath(__file__))
|
||||
|
||||
class MockFileClient(object):
|
||||
|
@ -20,7 +31,7 @@ class MockFileClient(object):
|
|||
'env': env
|
||||
})
|
||||
|
||||
class TestSaltCacheLoader(unittest.TestCase):
|
||||
class TestSaltCacheLoader(TestCase):
|
||||
def test_searchpath(self):
|
||||
'''
|
||||
The searchpath is based on the cachedir option and the env parameter
|
||||
|
@ -77,7 +88,7 @@ class TestSaltCacheLoader(unittest.TestCase):
|
|||
result = jinja.get_template('hello_include').render(a='Hi', b='Salt')
|
||||
self.assertEqual(result, 'Hey world !Hi Salt !')
|
||||
|
||||
class TestGetTemplate(unittest.TestCase):
|
||||
class TestGetTemplate(TestCase):
|
||||
def test_fallback(self):
|
||||
'''
|
||||
A Template without loader is returned as fallback
|
||||
|
|
Loading…
Add table
Reference in a new issue