blob: 8d9264f16b0b33264829f84c5d2d0e60588f35d1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
import os
import platform
import shutil
import tempfile
try:
import unittest2 as unittest
except ImportError:
import unittest
from leap.base.config import get_username, get_groupname
_system = platform.system()
class BaseLeapTest(unittest.TestCase):
__name__ = "leap_test"
@classmethod
def setUpClass(cls):
cls.old_path = os.environ['PATH']
cls.old_home = os.environ['HOME']
cls.tempdir = tempfile.mkdtemp(prefix="leap_tests-")
cls.home = cls.tempdir
bin_tdir = os.path.join(
cls.tempdir,
'bin')
os.environ["PATH"] = bin_tdir
os.environ["HOME"] = cls.tempdir
@classmethod
def tearDownClass(cls):
os.environ["PATH"] = cls.old_path
os.environ["HOME"] = cls.old_home
shutil.rmtree(cls.tempdir)
# you have to override these methods
# this way we ensure we did not put anything
# here that you can forget to call.
def setUp(self):
raise NotImplementedError("abstract base class")
def tearDown(self):
raise NotImplementedError("abstract base class")
#
# helper methods
#
def get_tempfile(self, filename):
return os.path.join(self.tempdir, filename)
def get_username(self):
return get_username()
def get_groupname(self):
return get_groupname()
def _missing_test_for_plat(self, do_raise=False):
if do_raise:
raise NotImplementedError(
"This test is not implemented "
"for the running platform: %s" %
_system)
|