Make sure every test module is runnable by __main__.

* Double to single quotes
This commit is contained in:
Pedro Algarvio 2013-06-24 23:53:59 +01:00
parent be54a503d9
commit 222be7b446
49 changed files with 843 additions and 330 deletions

View file

@ -31,6 +31,7 @@ import salt.output
from salt.utils import fopen, get_colors
from salt.utils.verify import verify_env
# Import Salt Testing libs
from salttesting import TestCase
from salttesting.parser import PNUM, print_header
from salttesting.helpers import RedirectStdStreams
@ -60,7 +61,7 @@ for dir_ in [CODE_DIR, SALT_LIBS]:
log = logging.getLogger(__name__)
def run_tests(TestCase):
def run_tests(TestCase, needs_daemon=True):
'''
Run integration tests for a chosen test case.
@ -92,15 +93,28 @@ def run_tests(TestCase):
def run_suite(self, testcase):
loader = TestLoader()
tests = loader.loadTestsFromTestCase(testcase)
if isinstance(testcase, list):
for case in testcase:
tests = loader.loadTestsFromTestCase(case)
else:
tests = loader.loadTestsFromTestCase(testcase)
print('Setting up Salt daemons to execute tests')
with TestDaemon(self):
header = '{0} Tests'.format(testcase.__name__)
print_header('Starting {0}'.format(header))
header = ''
if needs_daemon:
with TestDaemon(self):
if not isinstance(testcase, list):
header = '{0} Tests'.format(testcase.__name__)
print_header('Starting {0}'.format(header))
runner = TextTestRunner(
verbosity=self.options.verbosity).run(tests)
else:
if not isinstance(testcase, list):
header = '{0} Tests'.format(testcase.__name__)
print_header('Starting {0}'.format(header))
runner = TextTestRunner(
verbosity=self.options.verbosity).run(tests)
self.testsuite_results.append((header, runner))
return runner.wasSuccessful()
self.testsuite_results.append((header, runner))
return runner.wasSuccessful()
parser = TestcaseParser(INTEGRATION_TEST_DIR)
parser.parse_args()

View file

@ -2,9 +2,22 @@
import sys
# Import salt libs
from saltunittest import TestLoader, TextTestRunner
import integration
from integration import TestDaemon
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
# Import Salt Testing libs
from salttesting import TestLoader, TextTestRunner
class StdTest(integration.ModuleCase):
@ -89,9 +102,5 @@ class StdTest(integration.ModuleCase):
self.assertEqual(data['ret']['qux'], 'quux')
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(StdTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
from integration import run_tests
run_tests(StdTest)

View file

@ -2,9 +2,19 @@
import sys
# Import salt libs
from saltunittest import TestLoader, TextTestRunner
import integration
from integration import TestDaemon
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
class StdTest(integration.ModuleCase):
@ -57,18 +67,18 @@ class StdTest(integration.ModuleCase):
)
self.assertIn('minion', ret)
self.assertEqual(ret['minion'], {'ret': True, 'success': True})
ret = self.client.cmd_full_return(
'minion',
'test.pong',
)
self.assertIn('minion', ret)
self.assertEqual(ret['minion'], {'ret': '"test.pong" is not available.', 'success': False})
self.assertEqual(
ret['minion'],
{'ret': '"test.pong" is not available.', 'success': False}
)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(StdTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
from integration import run_tests
run_tests(StdTest)

View file

@ -2,9 +2,19 @@
import sys
# Import salt libs
from saltunittest import TestLoader, TextTestRunner
import integration
from integration import TestDaemon
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
class TestSyndic(integration.SyndicCase):
@ -29,10 +39,7 @@ class TestSyndic(integration.SyndicCase):
34
)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestSyndic)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
from integration import run_tests
run_tests(TestSyndic)

View file

@ -15,6 +15,7 @@ except ImportError:
)
import integration
# Import Salt Testing libs
from salttesting import skipIf
try:
@ -196,13 +197,18 @@ sys.stdout.write('cheese')
'''
cmd.run trigger timeout
'''
self.assertTrue('Timed out' in self.run_function('cmd.run', ['sleep 2 && echo hello', 'timeout=1']))
self.assertTrue(
'Timed out' in self.run_function(
'cmd.run', ['sleep 2 && echo hello', 'timeout=1']))
def test_timeout_success(self):
'''
cmd.run sufficient timeout to succeed
'''
self.assertTrue('hello' == self.run_function('cmd.run', ['sleep 1 && echo hello', 'timeout=2']))
self.assertTrue(
'hello' == self.run_function(
'cmd.run', ['sleep 1 && echo hello', 'timeout=2']))
if __name__ == '__main__':
from integration import run_tests

View file

@ -17,6 +17,8 @@ except ImportError:
import integration
from salt.modules import djangomod as django
# Import Salt Testing libs
from salttesting import skipIf
django.__salt__ = {}

View file

@ -20,6 +20,8 @@ except ImportError:
)
import integration
import salt.utils
# Import Salt Testing libs
from salttesting import skipIf
@ -163,6 +165,7 @@ class FileModuleTest(integration.ModuleCase):
'ERROR executing file.remove: File path must be absolute.', ret
)
if __name__ == '__main__':
from integration import run_tests
run_tests(FileModuleTest)

View file

@ -19,6 +19,8 @@ except ImportError:
)
)
import integration
# Import Salt Testing libs
from salttesting import skipIf
@ -105,7 +107,6 @@ class TestModulesGrains(integration.ModuleCase):
'foo')
if __name__ == '__main__':
from integration import run_tests
run_tests(TestModulesGrains)

View file

@ -17,7 +17,9 @@ except ImportError:
)
)
import integration
from salttesting import destructiveTest, skipIf
# Import Salt Testing libs
from salttesting import skipIf
from salttesting.helpers import destructiveTest

View file

@ -15,6 +15,8 @@ except ImportError:
)
)
import integration
# Import Salt Testing libs
from salttesting import skipIf
@ -47,7 +49,10 @@ class SysctlModuleTest(integration.ModuleCase):
def test_show_darwin(self):
ret = self.run_function('sysctl.show')
self.assertIn('kern.ostype', ret, 'kern.ostype absent')
self.assertEqual(ret.get('kern.ostype'), 'Darwin', 'Incorrect kern.ostype')
self.assertEqual(
ret.get('kern.ostype'), 'Darwin', 'Incorrect kern.ostype'
)
if __name__ == '__main__':
from integration import run_tests

View file

@ -17,7 +17,9 @@ except ImportError:
)
)
import integration
from saltunittest import skipIf
# Import Salt Testing libs
from salttesting import skipIf
from salttesting.helpers import destructiveTest

View file

@ -5,9 +5,19 @@ Tests for the salt-run command
import sys
# Import Salt Modules
from saltunittest import TestLoader, TextTestRunner
import integration
from integration import TestDaemon
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
class ManageTest(integration.ShellCase):
@ -37,10 +47,7 @@ class ManageTest(integration.ShellCase):
ret = self.run_run_plus('jobs.list_jobs')
self.assertIsInstance(ret['fun'], dict)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(ManageTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
if __name__ == '__main__':
from integration import run_tests
run_tests(ManageTest)

View file

@ -4,10 +4,20 @@ Tests for the salt-run command
# Import python libs
import sys
# Import Salt Modules
from saltunittest import TestLoader, TextTestRunner
import integration
from integration import TestDaemon
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
class ManageTest(integration.ShellCase):
@ -34,10 +44,7 @@ class ManageTest(integration.ShellCase):
self.assertNotIn('minion', ret['out'])
self.assertNotIn('sub_minion', ret['out'])
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(ManageTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
if __name__ == '__main__':
from integration import run_tests
run_tests(ManageTest)

View file

@ -2,13 +2,22 @@
Tests for the salt-run command
'''
# Import python libs
import sys
import os
import sys
# Import Salt Modules
from saltunittest import TestLoader, TextTestRunner
import integration
from integration import TestDaemon
try:
import integration
except ImportError:
if __name__ == '__main__':
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
class ManageTest(integration.ShellCase):
@ -32,10 +41,6 @@ class ManageTest(integration.ShellCase):
self.assertIn('Requisite fail_stage failed for stage', ret)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(ManageTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
if __name__ == '__main__':
from integration import run_tests
run_tests(ManageTest)

View file

@ -14,13 +14,22 @@ import sys
import yaml
from datetime import datetime
# Import salt test libs
import integration
from saltunittest import (
TestLoader,
TextTestRunner,
skipIf,
)
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
# Import Salt Testing libs
from salttesting import skipIf
class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
@ -179,10 +188,6 @@ class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
os.unlink(this_minion_key)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(CallTest)
print('Setting up Salt daemons to execute tests')
with integration.TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
if __name__ == '__main__':
from integration import run_tests
run_tests(CallTest)

View file

@ -15,9 +15,19 @@ import yaml
import pipes
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
import salt.utils
import integration
from saltunittest import TestLoader, TextTestRunner
class CopyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
@ -104,10 +114,7 @@ class CopyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
data = yaml.load('\n'.join(ret))
self.assertTrue(data[minion])
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(CopyTest)
print('Setting up Salt daemons to execute tests')
with integration.TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
if __name__ == '__main__':
from integration import run_tests
run_tests(CopyTest)

View file

@ -5,14 +5,21 @@ import shutil
import tempfile
# Import salt libs
from salt import version
from saltunittest import TestLoader, TextTestRunner
import integration
from integration import TestDaemon
try:
import integration
except ImportError:
if __name__ == '__main__':
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
class KeyTest(integration.ShellCase,
integration.ShellCaseCommonTestsMixIn):
class KeyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
'''
Test salt-key script
'''
@ -133,16 +140,13 @@ class KeyTest(integration.ShellCase,
arg_str + ' --keysize=32769', catch_stderr=True
)
self.assertIn(
'salt-key: error: The maximum value for keysize is 32768', error
'salt-key: error: The maximum value for keysize is 32768',
error
)
finally:
shutil.rmtree(tempdir)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(KeyTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
if __name__ == '__main__':
from integration import run_tests
run_tests(KeyTest)

View file

@ -12,8 +12,19 @@
import sys
# Import salt libs
from saltunittest import TestLoader, TextTestRunner
import integration
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
class MasterTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
@ -21,10 +32,6 @@ class MasterTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
_call_binary_ = 'salt-master'
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(MasterTest)
print('Setting up Salt daemons to execute tests')
with integration.TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
if __name__ == '__main__':
from integration import run_tests
run_tests(MasterTest)

View file

@ -3,9 +3,19 @@ import sys
import yaml
# Import salt libs
from saltunittest import TestLoader, TextTestRunner
import integration
from integration import TestDaemon
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
class MatchTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
@ -54,7 +64,6 @@ class MatchTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
self.assertIn('sub_minion', data)
self.assertNotIn('minion', data.replace('sub_minion', 'stub'))
def test_glob(self):
'''
test salt glob matcher
@ -222,10 +231,6 @@ class MatchTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
self.assertIn('user.add:', data)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(MatchTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
if __name__ == '__main__':
from integration import run_tests
run_tests(MatchTest)

View file

@ -12,8 +12,19 @@
import sys
# Import salt libs
from saltunittest import TestLoader, TextTestRunner
import integration
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
class MinionTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
@ -21,10 +32,6 @@ class MinionTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
_call_binary_ = 'salt-minion'
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(MinionTest)
print('Setting up Salt daemons to execute tests')
with integration.TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
if __name__ == '__main__':
from integration import run_tests
run_tests(MinionTest)

View file

@ -5,9 +5,19 @@ Tests for the salt-run command
import sys
# Import Salt Modules
from saltunittest import TestLoader, TextTestRunner
import integration
from integration import TestDaemon
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
class RunTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
@ -39,10 +49,7 @@ class RunTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
data = '\n'.join(data)
self.assertNotIn('jobs.SaltException:', data)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(RunTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
if __name__ == '__main__':
from integration import run_tests
run_tests(RunTest)

View file

@ -12,8 +12,19 @@
import sys
# Import salt libs
from saltunittest import TestLoader, TextTestRunner
import integration
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
class SyndicTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
@ -21,10 +32,6 @@ class SyndicTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
_call_binary_ = 'salt-syndic'
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(SyndicTest)
print('Setting up Salt daemons to execute tests')
with integration.TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())
if __name__ == '__main__':
from integration import run_tests
run_tests(SyndicTest)

View file

@ -12,10 +12,23 @@
import os
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
import salt.utils
import integration
from saltunittest import skipIf
# Import Salt Testing libs
from salttesting import skipIf
STATE_DIR = os.path.join(integration.FILES, 'file', 'base')
@ -53,3 +66,8 @@ class StateMatchTest(integration.ModuleCase):
)
finally:
os.remove(top_file)
if __name__ == '__main__':
from integration import run_tests
run_tests(StateMatchTest)

View file

@ -19,6 +19,8 @@ except ImportError:
)
)
import integration
# Import Salt Testing libs
from salttesting import skipIf
from salttesting.helpers import destructiveTest
@ -120,6 +122,7 @@ class UserTest(integration.ModuleCase,
ret = self.run_state('group.absent', name='salt_test')
self.assertSaltTrueReturn(ret)
if __name__ == '__main__':
from integration import run_tests
run_tests(UserTest)

View file

@ -13,9 +13,23 @@ import os
import shutil
# Import salt libs
import integration
try:
import integration
except ImportError:
if __name__ == '__main__':
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
from saltunittest import skipIf, destructiveTest
# Import Salt Testing libs
from salttesting import skipIf
from salttesting.helpers import destructiveTest
class VirtualenvTest(integration.ModuleCase,
@ -137,3 +151,8 @@ class VirtualenvTest(integration.ModuleCase,
shutil.rmtree(venv_path)
if os.path.exists(requirements_file_path):
os.unlink(requirements_file_path)
if __name__ == '__main__':
from integration import run_tests
run_tests(VirtualenvTest)

View file

@ -11,9 +11,11 @@ import resource
import tempfile
# Import salt libs
from integration import TestDaemon, TMP
# Import Salt Testing libs
from salttesting import *
from salttesting.parser import PNUM, print_header, SaltTestingParser
from integration import TestDaemon, TMP
TEST_DIR = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))
SALT_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))

View file

@ -14,10 +14,25 @@ import shutil
import tempfile
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../'
)
)
)
import integration
import salt.utils
from saltunittest import TestCase, TestLoader, TextTestRunner
from salt import config as sconfig
# Import Salt Testing libs
from salttesting import TestCase
class ConfigTestCase(TestCase):
def test_proper_path_joining(self):
@ -46,7 +61,6 @@ class ConfigTestCase(TestCase):
shutil.rmtree(tempdir)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(ConfigTestCase)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(ConfigTestCase, needs_daemon=False)

View file

@ -11,9 +11,24 @@
'''
# Import salt libs
from saltunittest import (
TestCase, TestLoader, TextTestRunner, TestsLoggingHandler
)
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../'
)
)
)
import integration
# Import Salt Testing libs
from salttesting import TestCase
from salttesting.helpers import TestsLoggingHandler
class TestLog(TestCase):
@ -64,7 +79,6 @@ class TestLog(TestCase):
log.removeHandler(handler)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestLog)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(TestLog, needs_daemon=False)

View file

@ -1,6 +1,24 @@
from saltunittest import TestCase
# Import salt modules
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
from salt.modules import config
# Import Salt Testing libs
from salttesting import TestCase
config.__opts__ = {
"test.option.all": "value of test.option.all in __opts__"
@ -40,3 +58,8 @@ class TestModulesConfig(TestCase):
omit_pillar=True)
self.assertEqual(opt, config.__pillar__['master'][opt_name])
if __name__ == '__main__':
from integration import run_tests
run_tests(TestModulesConfig, needs_daemon=False)

View file

@ -1,10 +1,26 @@
import tempfile
from saltunittest import TestCase, TestLoader, TextTestRunner
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
from salt.modules import file as filemod
from salt.modules import cmdmod
# Import Salt Testing libs
from salttesting import TestCase
filemod.__salt__ = {
'cmd.run': cmdmod.run,
'cmd.run_all': cmdmod.run_all
@ -38,7 +54,6 @@ class FileModuleTestCase(TestCase):
)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(FileModuleTestCase)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(FileModuleTestCase, needs_daemon=False)

View file

@ -1,20 +1,38 @@
import sys
import os
sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
from saltunittest import TestCase, TestLoader, TextTestRunner, skipIf
# Import python libs
import os
import sys
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
import salt.modules.gem as gem
# Import Salt Testing libs
from salttesting import TestCase, skipIf
# Import external libs
try:
from mock import MagicMock, patch
has_mock = True
except ImportError:
has_mock = False
import salt.modules.gem as gem
gem.__salt__ = {}
@skipIf(has_mock is False, "mock python module is unavailable")
@skipIf(has_mock is False, 'mock python module is unavailable')
class TestGemModule(TestCase):
def test__gem(self):
@ -22,16 +40,16 @@ class TestGemModule(TestCase):
with patch.dict(gem.__salt__,
{'rvm.is_installed': MagicMock(return_value=False),
'cmd.run_all': mock}):
gem._gem("install rails")
mock.assert_called_once_with("gem install rails", runas=None)
gem._gem('install rails')
mock.assert_called_once_with('gem install rails', runas=None)
mock = MagicMock(return_value=None)
with patch.dict(gem.__salt__,
{'rvm.is_installed': MagicMock(return_value=True),
'rvm.do': mock}):
gem._gem("install rails", ruby="1.9.3")
gem._gem('install rails', ruby='1.9.3')
mock.assert_called_once_with(
"1.9.3", "gem install rails", runas=None
'1.9.3', 'gem install rails', runas=None
)
def test_list(self):
@ -69,7 +87,6 @@ http://rubygems.org/
['http://rubygems.org/'], gem.sources_list())
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestGemModule)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(TestGemModule, needs_daemon=False)

View file

@ -5,7 +5,7 @@ except ImportError:
has_mock = False
patch = lambda x: lambda y: None
from saltunittest import TestCase, skipIf
from salttesting import TestCase, skipIf
from salt.modules import pip
pip.__salt__ = {"cmd.which_bin":lambda _:"pip"}

View file

@ -9,7 +9,7 @@ except ImportError:
return lambda y: None
patch.multiple = patchmultiple
from saltunittest import TestCase, TestLoader, TextTestRunner, skipIf
from salttesting import TestCase, TestLoader, TextTestRunner, skipIf
from salt.modules import postgres
postgres.__grains__ = None # in order to stub it w/patch below

View file

@ -1,9 +1,25 @@
import sys
# Import python libs
import os
sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
import sys
from saltunittest import TestCase, TestLoader, TextTestRunner, skipIf
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
# Import Salt Testing libs
from salttesting import TestCase, skipIf
# Import external libs
try:
from mock import MagicMock, patch
has_mock = True
@ -14,26 +30,26 @@ if has_mock:
import salt.modules.rvm as rvm
rvm.__salt__ = {
'cmd.has_exec': MagicMock(return_value=True),
'config.option' : MagicMock(return_value=None)
'config.option': MagicMock(return_value=None)
}
@skipIf(has_mock is False, "mock python module is unavailable")
@skipIf(has_mock is False, 'mock python module is unavailable')
class TestRvmModule(TestCase):
def test__rvm(self):
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
with patch.dict(rvm.__salt__, {'cmd.run_all': mock}):
rvm._rvm("install", "1.9.3")
rvm._rvm('install', '1.9.3')
mock.assert_called_once_with(
"/usr/local/rvm/bin/rvm install 1.9.3", runas=None
'/usr/local/rvm/bin/rvm install 1.9.3', runas=None
)
def test__rvm_do(self):
mock = MagicMock(return_value=None)
with patch.object(rvm, '_rvm', new=mock):
rvm._rvm_do("1.9.3", "gemset list")
mock.assert_called_once_with("1.9.3 do gemset list", runas=None)
rvm._rvm_do('1.9.3', 'gemset list')
mock.assert_called_once_with('1.9.3 do gemset list', runas=None)
def test_install(self):
mock = MagicMock(return_value=0)
@ -118,7 +134,7 @@ gemsets for ruby-1.9.2-p180 (found in /usr/local/rvm/gems/ruby-1.9.2-p180)
'ruby-head': ['global', 'headbar', 'headfoo']},
rvm.gemset_list_all())
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestRvmModule)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(TestRvmModule, needs_daemon=False)

View file

@ -1,13 +1,26 @@
# Import python libs
import os
import new
import sys
import os
if __name__ == '__main__':
sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
)
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
from saltunittest import TestCase, TestLoader, TextTestRunner, skipIf
# Import Salt Testing libs
from salttesting import TestCase, skipIf
# wmi and pythoncom modules are platform specific...
@ -34,13 +47,14 @@ try:
except ImportError:
has_mock = False
# This is imported late so mock can do it's job
import salt.modules.win_status as status
@skipIf(has_mock is False,
wrong_version and
"you need to upgrade your mock version to >= 0.8.0" or
"mock python module is unavailable")
'you need to upgrade your mock version to >= 0.8.0' or
'mock python module is unavailable')
class TestProcsBase(TestCase):
def __init__(self, *args, **kwargs):
TestCase.__init__(self, *args, **kwargs)
@ -55,7 +69,9 @@ class TestProcsBase(TestCase):
user_domain='domain',
get_owner_result=0):
process = Mock()
process.GetOwner = Mock(return_value=(user_domain, get_owner_result, user))
process.GetOwner = Mock(
return_value=(user_domain, get_owner_result, user)
)
process.ProcessId = pid
process.CommandLine = cmd
process.Name = name
@ -137,8 +153,8 @@ class TestProcsUnicodeAttributes(TestProcsBase):
class TestProcsWMIGetOwnerAccessDeniedWorkaround(TestProcsBase):
def setUp(self):
self.expected_user = "SYSTEM"
self.expected_domain = "NT AUTHORITY"
self.expected_user = 'SYSTEM'
self.expected_domain = 'NT AUTHORITY'
self.add_process(pid=0, get_owner_result=2)
self.add_process(pid=4, get_owner_result=2)
self.call_procs()
@ -161,7 +177,10 @@ class TestProcsWMIGetOwnerErrorsAreLogged(TestProcsBase):
with patch('salt.modules.win_status.log') as log:
self.call_procs()
log.warning.assert_called_once_with(ANY)
self.assertIn(str(self.expected_error_code), log.warning.call_args[0][0])
self.assertIn(
str(self.expected_error_code),
log.warning.call_args[0][0]
)
class TestEmptyCommandLine(TestProcsBase):
@ -188,12 +207,15 @@ class TestEmptyCommandLine(TestProcsBase):
# pythoncom.CoUninitialize.assert_has_calls(self.expected_calls)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestProcsCount)
tests = loader.loadTestsFromTestCase(TestProcsAttributes)
tests = loader.loadTestsFromTestCase(TestProcsUnicodeAttributes)
tests = loader.loadTestsFromTestCase(
TestProcsWMIGetOwnerAccessDeniedWorkaround)
tests = loader.loadTestsFromTestCase(TestProcsWMIGetOwnerErrorsAreLogged)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(
[
TestProcsCount,
TestProcsAttributes,
TestProcsUnicodeAttributes,
TestProcsWMIGetOwnerErrorsAreLogged,
TestProcsWMIGetOwnerAccessDeniedWorkaround,
],
needs_daemon=False
)

View file

@ -5,12 +5,27 @@ import tempfile
from cStringIO import StringIO
# Import Salt libs
from saltunittest import TestCase
try:
import integration
except ImportError:
if __name__ == '__main__':
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../'
)
)
)
import integration
import salt.loader
import salt.config
from salt.state import HighState
from salt.utils.pydsl import PyDslError
# Import Salt Testing libs
from salttesting import TestCase
REQUISITES = ['require', 'require_in', 'use', 'use_in', 'watch', 'watch_in']
OPTS = salt.config.minion_config(None, check_dns=False)
@ -440,3 +455,8 @@ def state_highstate(matches, dirpath):
# pprint.pprint(out)
finally:
HIGHSTATE.pop_active()
if __name__ == '__main__':
from integration import run_tests
run_tests(PyDSLRendererTestCase, needs_daemon=False)

View file

@ -1,4 +1,4 @@
from saltunittest import TestCase, expectedFailure
from salttesting import TestCase, expectedFailure
class SimpleTest(TestCase):

View file

@ -2,10 +2,27 @@
from cStringIO import StringIO
# Import Salt libs
from saltunittest import TestCase
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../'
)
)
)
import integration
import salt.loader
import salt.config
# Import Salt Testing libs
from salttesting import TestCase
REQUISITES = ['require', 'require_in', 'use', 'use_in', 'watch', 'watch_in']
OPTS = salt.config.minion_config(None, check_dns=False)
@ -256,3 +273,8 @@ G:
[i.itervalues().next() for i in goal_args[0]['require']],
list('ABCDEFG')
)
if __name__ == '__main__':
from integration import run_tests
run_tests(StateConfigRendererTestCase, needs_daemon=False)

View file

@ -1,25 +1,42 @@
import sys
# Import python libs
import os
sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
import sys
from saltunittest import TestCase, TestLoader, TextTestRunner, skipIf
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
# Import Salt Testing libs
from salttesting import TestCase, skipIf
# Import external libs
try:
from mock import MagicMock, patch
has_mock = True
except ImportError:
has_mock = False
# Late import so mock can do it's job
import salt.states.gem as gem
gem.__salt__ = {}
gem.__opts__ = {'test': False}
@skipIf(has_mock is False, "mock python module is unavailable")
@skipIf(has_mock is False, 'mock python module is unavailable')
class TestGemState(TestCase):
def test_installed(self):
gems = {'foo' : ['1.0'], 'bar' : ['2.0']}
gems = {'foo': ['1.0'], 'bar': ['2.0']}
gem_list = MagicMock(return_value=gems)
gem_install_succeeds = MagicMock(return_value=True)
gem_install_fails = MagicMock(return_value=False)
@ -32,14 +49,18 @@ class TestGemState(TestCase):
ret = gem.installed('quux')
self.assertEqual(True, ret['result'])
gem_install_succeeds.assert_called_once_with(
'quux', ruby=None, runas=None, version=None, rdoc=False, ri=False)
'quux', ruby=None, runas=None, version=None, rdoc=False,
ri=False
)
with patch.dict(gem.__salt__,
{'gem.install': gem_install_fails}):
ret = gem.installed('quux')
self.assertEqual(False, ret['result'])
gem_install_fails.assert_called_once_with(
'quux', ruby=None, runas=None, version=None, rdoc=False, ri=False)
'quux', ruby=None, runas=None, version=None, rdoc=False,
ri=False
)
def test_removed(self):
gems = ['foo', 'bar']
@ -63,7 +84,7 @@ class TestGemState(TestCase):
gem_uninstall_fails.assert_called_once_with(
'bar', None, runas=None)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestGemState)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(TestGemState, needs_daemon=False)

View file

@ -1,9 +1,24 @@
import sys
# Import python libs
import os
sys.path.insert(
0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
import sys
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
# Import Salt Testing libs
from salttesting import TestCase, skipIf
from saltunittest import TestCase, TestLoader, TextTestRunner, skipIf
try:
from mock import MagicMock, patch
has_mock = True
@ -22,7 +37,7 @@ if has_mock:
}
@skipIf(has_mock is False, "mock python module is unavailable")
@skipIf(has_mock is False, 'mock python module is unavailable')
class TestRvmState(TestCase):
def test__check_rvm(self):
@ -40,7 +55,7 @@ class TestRvmState(TestCase):
return_value={'changes': {}, 'result': True})
mock_check_ruby = MagicMock(
return_value={'changes': {}, 'result': False})
mock_install_ruby = MagicMock(return_value="")
mock_install_ruby = MagicMock(return_value='')
with patch.object(rvm, '_check_rvm', new=mock_check_rvm):
with patch.object(rvm, '_check_ruby', new=mock_check_ruby):
with patch.dict(rvm.__salt__,
@ -91,12 +106,11 @@ class TestRvmState(TestCase):
with patch.object(rvm, '_check_rvm') as mock_method:
mock_method.return_value = {'result': True}
with patch.object(rvm, '_check_and_install_ruby', new=mock):
rvm.installed("1.9.3", default=True)
rvm.installed('1.9.3', default=True)
mock.assert_called_once_with(
{'result': True}, '1.9.3', True, runas=None)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestRvmState)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(TestRvmState, needs_daemon=False)

View file

@ -2,14 +2,29 @@
import os
import tempfile
# Import 3rd party libs
from jinja2 import Environment
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
import salt.utils
from salt.utils.jinja import SaltCacheLoader
from salt.utils.templates import render_jinja_tmpl
from saltunittest import TestCase
# Import Salt Testing libs
from salttesting import TestCase
# Import 3rd party libs
from jinja2 import Environment
TEMPLATES_DIR = os.path.dirname(os.path.abspath(__file__))
@ -54,7 +69,7 @@ class TestSaltCacheLoader(TestCase):
self.assertEqual(str(res[0]), 'world' + os.linesep)
tmpl_dir = os.path.join(TEMPLATES_DIR, 'files', 'test', 'hello_simple')
self.assertEqual(res[1], tmpl_dir)
assert res[2](), "Template up to date?"
assert res[2](), 'Template up to date?'
assert len(fc.requests)
self.assertEqual(fc.requests[0]['path'], 'salt://hello_simple')
@ -152,3 +167,8 @@ class TestGetTemplate(TestCase):
self.assertEqual(out, 'Hey world !Hi Salt !\n')
self.assertEqual(fc.requests[0]['path'], 'salt://macro')
SaltCacheLoader.file_client = _fc
if __name__ == '__main__':
from integration import run_tests
run_tests([TestSaltCacheLoader, TestGetTemplate], needs_daemon=False)

View file

@ -13,10 +13,24 @@ import os
import hashlib
# Import salt libs
import integration
from saltunittest import TestCase, TestLoader, TextTestRunner
try:
import integration
except ImportError:
if __name__ == '__main__':
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
from salt.utils import event
# Import Salt Testing libs
from salttesting import TestCase
SOCK_DIR = os.path.join(integration.TMP, 'test-socks')
@ -25,8 +39,7 @@ class TestSaltEvent(TestCase):
def test_master_event(self):
me = event.MasterEvent(SOCK_DIR)
self.assertEqual(
me.puburi,
'ipc://{0}'.format(
me.puburi, 'ipc://{0}'.format(
os.path.join(SOCK_DIR, 'master_event_pub.ipc')
)
)
@ -85,7 +98,6 @@ class TestSaltEvent(TestCase):
)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestSaltEvent)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(TestSaltEvent, needs_daemon=False)

View file

@ -9,9 +9,25 @@
'''
# Import salt libs
from saltunittest import TestCase, TestLoader, TextTestRunner
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
from salt.utils.filebuffer import BufferedReader, InvalidFileMode
# Import Salt Testing libs
from salttesting import TestCase
class TestFileBuffer(TestCase):
def test_read_only_mode(self):
@ -28,7 +44,6 @@ class TestFileBuffer(TestCase):
BufferedReader('/tmp/foo', mode='wb')
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestFileBuffer)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(TestFileBuffer, needs_daemon=False)

View file

@ -6,9 +6,23 @@ import tempfile
import stat
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
import salt.utils
import salt.utils.find
from saltunittest import TestCase, TestLoader, TextTestRunner, skipIf
# Import Salt Testing libs
from salttesting import TestCase, skipIf
class TestFind(TestCase):
@ -554,10 +568,9 @@ class TestFinder(TestCase):
)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestFind)
tests.addTests(loader.loadTestsFromTestCase(TestGrepOption))
tests.addTests(loader.loadTestsFromTestCase(TestPrintOption))
tests.addTests(loader.loadTestsFromTestCase(TestFinder))
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(
[TestFind, TestGrepOption, TestPrintOption, TestFinder],
needs_daemon=False
)

View file

@ -16,15 +16,25 @@ import ntpath
import platform
import tempfile
if __name__ == "__main__":
sys.path.insert(
0, os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
)
# Import salt libs
from saltunittest import TestCase, TextTestRunner
try:
import integration
except ImportError:
if __name__ == '__main__':
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
from salt.utils import path_join
# Import Salt Testing libs
from salttesting import TestCase
class PathJoinTestCase(TestCase):
@ -117,7 +127,7 @@ class PathJoinTestCase(TestCase):
for module in (posixpath, os, os.path, tempfile, platform):
reload(module)
if __name__ == "__main__":
loader = PathJoinTestCase()
tests = loader.loadTestsFromTestCase(PathJoinTestCase)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(PathJoinTestCase, needs_daemon=False)

View file

@ -12,25 +12,40 @@
import re
# Import salt libs
from saltunittest import TestCase, TestLoader, TextTestRunner
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
from salt.utils import build_whitespace_split_regex
# Import Salt Testing libs
from salttesting import TestCase
DOUBLE_TXT = """\
DOUBLE_TXT = '''\
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
"""
'''
SINGLE_TXT = """\
SINGLE_TXT = '''\
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z '$debian_chroot' ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
"""
'''
SINGLE_DOUBLE_TXT = """\
SINGLE_DOUBLE_TXT = '''\
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z '$debian_chroot' ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
@ -40,16 +55,16 @@ fi
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
"""
'''
SINGLE_DOUBLE_SAME_LINE_TXT = """\
SINGLE_DOUBLE_SAME_LINE_TXT = '''\
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z '$debian_chroot' ] && [ -r "/etc/debian_chroot" ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
"""
'''
MATCH = """\
MATCH = '''\
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z '$debian_chroot' ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
@ -78,7 +93,7 @@ fi
if [ -z '$debian_chroot' ] && [ -r "/etc/debian_chroot" ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
"""
'''
class TestRuntimeWhitespaceRegex(TestCase):
@ -100,7 +115,6 @@ class TestRuntimeWhitespaceRegex(TestCase):
self.assertTrue(re.search(regex, MATCH))
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(TestRuntimeWhitespaceRegex)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(TestRuntimeWhitespaceRegex, needs_daemon=False)

View file

@ -1,12 +1,29 @@
# Import python libs
import os
from os.path import join
from shutil import rmtree
from tempfile import mkdtemp
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
import salt.utils
import salt.utils.find
from saltunittest import TestCase, TestLoader, TextTestRunner, skipIf
# Import Salt Testing libs
from salttesting import TestCase, skipIf
class TestUtils(TestCase):
@ -15,11 +32,11 @@ class TestUtils(TestCase):
tmp = mkdtemp()
try:
if os.stat(tmp).st_ino == 0:
self.skipTest("inodes not supported in {0}".format(tmp))
os.mkdir(join(tmp, "fax"))
os.makedirs(join(tmp, "foo/bar"))
os.symlink("../..", join(tmp, "foo/bar/baz"))
os.symlink("foo", join(tmp, "root"))
self.skipTest('inodes not supported in {0}'.format(tmp))
os.mkdir(join(tmp, 'fax'))
os.makedirs(join(tmp, 'foo/bar'))
os.symlink('../..', join(tmp, 'foo/bar/baz'))
os.symlink('foo', join(tmp, 'root'))
expected = [
(join(tmp, 'root'), ['bar'], []),
(join(tmp, 'root/bar'), ['baz'], []),
@ -27,11 +44,19 @@ class TestUtils(TestCase):
(join(tmp, 'root/bar/baz/fax'), [], []),
]
paths = []
for root, dirs, names in salt.utils.safe_walk(join(tmp, "root")):
for root, dirs, names in salt.utils.safe_walk(join(tmp, 'root')):
paths.append((root, sorted(dirs), names))
if paths != expected:
raise AssertionError("\n".join(["got:"]
+ [repr(p) for p in paths]
+ ["", "expected:"] + [repr(p) for p in expected]))
raise AssertionError(
'\n'.join(
['got:'] + [repr(p) for p in paths] +
['', 'expected:'] + [repr(p) for p in expected]
)
)
finally:
rmtree(tmp)
if __name__ == '__main__':
from integration import run_tests
run_tests(TestUtils, needs_daemon=False)

View file

@ -12,10 +12,20 @@ import resource
import tempfile
import socket
# Import Salt libs
# Import salt libs
try:
import integration
except ImportError:
if __name__ == '__main__':
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../../'
)
)
)
import integration
import salt.utils
from saltunittest import skipIf, TestCase, TestsLoggingHandler
from salt.utils.verify import (
check_user,
verify_env,
@ -24,6 +34,10 @@ from salt.utils.verify import (
check_max_open_files
)
# Import Salt Testing libs
from salttesting import skipIf, TestCase
from salttesting.helpers import TestsLoggingHandler
class TestVerify(TestCase):
'''
@ -184,3 +198,8 @@ class TestVerify(TestCase):
finally:
shutil.rmtree(tempdir)
resource.setrlimit(resource.RLIMIT_NOFILE, (mof_s, mof_h))
if __name__ == '__main__':
from integration import run_tests
run_tests(TestVerify, needs_daemon=False)

View file

@ -14,9 +14,25 @@
import re
# Import salt libs
from saltunittest import TestCase, TestLoader, TextTestRunner
try:
import integration
except ImportError:
if __name__ == '__main__':
import os
import sys
sys.path.insert(
0, os.path.abspath(
os.path.join(
os.path.dirname(__file__), '../'
)
)
)
import integration
import salt.version
# Import Salt Testing libs
from salttesting import TestCase
class VersionTestCase(TestCase):
def test_git_describe_re(self):
@ -33,7 +49,7 @@ class VersionTestCase(TestCase):
groups, re.search(salt.version.GIT_DESCRIBE_REGEX, vs).groups()
)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromVersionTestCase(VersionTestCase)
TextTestRunner(verbosity=1).run(tests)
if __name__ == '__main__':
from integration import run_tests
run_tests(VersionTestCase, needs_daemon=False)