1
# Copyright 2012 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Tests for `TestCase`."""
6
from __future__ import (
16
from shutil import rmtree
17
from tempfile import mkdtemp
19
from maastesting.testcase import TestCase
20
from testtools.matchers import (
26
class TestTestCase(TestCase):
27
"""Tests the base `TestCase` facilities."""
29
def test_make_dir_creates_directory(self):
30
self.assertThat(self.make_dir(), DirExists())
32
def test_make_dir_creates_temporary_directory(self):
33
other_temp_dir = mkdtemp()
34
self.addCleanup(rmtree, other_temp_dir)
35
other_temp_root, other_subdir = os.path.split(other_temp_dir)
36
temp_root, subdir = os.path.split(self.make_dir())
37
self.assertEqual(other_temp_root, temp_root)
38
self.assertNotIn(subdir, [b'', u'', None])
40
def test_make_dir_creates_one_directory_per_call(self):
41
self.assertNotEqual(self.make_dir(), self.make_dir())
43
def test_make_file_creates_file(self):
44
self.assertThat(self.make_file(), FileExists())
46
def test_make_file_uses_temporary_directory(self):
47
directory = self.make_dir()
48
self.patch(self, 'make_dir', lambda: directory)
49
dir_part, file_part = os.path.split(self.make_file())
50
self.assertEqual(directory, dir_part)