Move filesystem tests.
This commit is contained in:
@@ -8,10 +8,12 @@ def test_suite():
|
|||||||
from testtools.tests.matchers import (
|
from testtools.tests.matchers import (
|
||||||
test_basic,
|
test_basic,
|
||||||
test_core,
|
test_core,
|
||||||
|
test_filesystem,
|
||||||
)
|
)
|
||||||
modules = [
|
modules = [
|
||||||
test_basic,
|
test_basic,
|
||||||
test_core,
|
test_core,
|
||||||
|
test_filesystem,
|
||||||
]
|
]
|
||||||
suites = map(lambda x: x.test_suite(), modules)
|
suites = map(lambda x: x.test_suite(), modules)
|
||||||
return TestSuite(suites)
|
return TestSuite(suites)
|
||||||
|
|||||||
@@ -4,11 +4,7 @@
|
|||||||
|
|
||||||
import doctest
|
import doctest
|
||||||
import re
|
import re
|
||||||
import os
|
|
||||||
import shutil
|
|
||||||
import sys
|
import sys
|
||||||
import tarfile
|
|
||||||
import tempfile
|
|
||||||
|
|
||||||
from testtools import (
|
from testtools import (
|
||||||
Matcher, # check that Matcher is exposed at the top level for docs.
|
Matcher, # check that Matcher is exposed at the top level for docs.
|
||||||
@@ -30,13 +26,8 @@ from testtools.matchers import (
|
|||||||
ContainsAll,
|
ContainsAll,
|
||||||
ContainedByDict,
|
ContainedByDict,
|
||||||
ContainsDict,
|
ContainsDict,
|
||||||
DirContains,
|
|
||||||
DirExists,
|
|
||||||
DocTestMatches,
|
DocTestMatches,
|
||||||
Equals,
|
Equals,
|
||||||
FileContains,
|
|
||||||
FileExists,
|
|
||||||
HasPermissions,
|
|
||||||
KeysEqual,
|
KeysEqual,
|
||||||
LessThan,
|
LessThan,
|
||||||
MatchesAny,
|
MatchesAny,
|
||||||
@@ -54,10 +45,8 @@ from testtools.matchers import (
|
|||||||
MismatchError,
|
MismatchError,
|
||||||
Not,
|
Not,
|
||||||
NotEquals,
|
NotEquals,
|
||||||
PathExists,
|
|
||||||
Raises,
|
Raises,
|
||||||
raises,
|
raises,
|
||||||
SamePath,
|
|
||||||
_SubDictOf,
|
_SubDictOf,
|
||||||
TarballContains,
|
TarballContains,
|
||||||
)
|
)
|
||||||
@@ -831,160 +820,6 @@ class TestAllMatch(TestCase, TestMatchersInterface):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class PathHelpers(object):
|
|
||||||
|
|
||||||
def mkdtemp(self):
|
|
||||||
directory = tempfile.mkdtemp()
|
|
||||||
self.addCleanup(shutil.rmtree, directory)
|
|
||||||
return directory
|
|
||||||
|
|
||||||
def create_file(self, filename, contents=''):
|
|
||||||
fp = open(filename, 'w')
|
|
||||||
try:
|
|
||||||
fp.write(contents)
|
|
||||||
finally:
|
|
||||||
fp.close()
|
|
||||||
|
|
||||||
def touch(self, filename):
|
|
||||||
return self.create_file(filename)
|
|
||||||
|
|
||||||
|
|
||||||
class TestPathExists(TestCase, PathHelpers):
|
|
||||||
|
|
||||||
def test_exists(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
self.assertThat(tempdir, PathExists())
|
|
||||||
|
|
||||||
def test_not_exists(self):
|
|
||||||
doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
|
|
||||||
mismatch = PathExists().match(doesntexist)
|
|
||||||
self.assertThat(
|
|
||||||
"%s does not exist." % doesntexist, Equals(mismatch.describe()))
|
|
||||||
|
|
||||||
|
|
||||||
class TestDirExists(TestCase, PathHelpers):
|
|
||||||
|
|
||||||
def test_exists(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
self.assertThat(tempdir, DirExists())
|
|
||||||
|
|
||||||
def test_not_exists(self):
|
|
||||||
doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
|
|
||||||
mismatch = DirExists().match(doesntexist)
|
|
||||||
self.assertThat(
|
|
||||||
PathExists().match(doesntexist).describe(),
|
|
||||||
Equals(mismatch.describe()))
|
|
||||||
|
|
||||||
def test_not_a_directory(self):
|
|
||||||
filename = os.path.join(self.mkdtemp(), 'foo')
|
|
||||||
self.touch(filename)
|
|
||||||
mismatch = DirExists().match(filename)
|
|
||||||
self.assertThat(
|
|
||||||
"%s is not a directory." % filename, Equals(mismatch.describe()))
|
|
||||||
|
|
||||||
|
|
||||||
class TestFileExists(TestCase, PathHelpers):
|
|
||||||
|
|
||||||
def test_exists(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
filename = os.path.join(tempdir, 'filename')
|
|
||||||
self.touch(filename)
|
|
||||||
self.assertThat(filename, FileExists())
|
|
||||||
|
|
||||||
def test_not_exists(self):
|
|
||||||
doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
|
|
||||||
mismatch = FileExists().match(doesntexist)
|
|
||||||
self.assertThat(
|
|
||||||
PathExists().match(doesntexist).describe(),
|
|
||||||
Equals(mismatch.describe()))
|
|
||||||
|
|
||||||
def test_not_a_file(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
mismatch = FileExists().match(tempdir)
|
|
||||||
self.assertThat(
|
|
||||||
"%s is not a file." % tempdir, Equals(mismatch.describe()))
|
|
||||||
|
|
||||||
|
|
||||||
class TestDirContains(TestCase, PathHelpers):
|
|
||||||
|
|
||||||
def test_empty(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
self.assertThat(tempdir, DirContains([]))
|
|
||||||
|
|
||||||
def test_not_exists(self):
|
|
||||||
doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
|
|
||||||
mismatch = DirContains([]).match(doesntexist)
|
|
||||||
self.assertThat(
|
|
||||||
PathExists().match(doesntexist).describe(),
|
|
||||||
Equals(mismatch.describe()))
|
|
||||||
|
|
||||||
def test_contains_files(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
self.touch(os.path.join(tempdir, 'foo'))
|
|
||||||
self.touch(os.path.join(tempdir, 'bar'))
|
|
||||||
self.assertThat(tempdir, DirContains(['bar', 'foo']))
|
|
||||||
|
|
||||||
def test_matcher(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
self.touch(os.path.join(tempdir, 'foo'))
|
|
||||||
self.touch(os.path.join(tempdir, 'bar'))
|
|
||||||
self.assertThat(tempdir, DirContains(matcher=Contains('bar')))
|
|
||||||
|
|
||||||
def test_neither_specified(self):
|
|
||||||
self.assertRaises(AssertionError, DirContains)
|
|
||||||
|
|
||||||
def test_both_specified(self):
|
|
||||||
self.assertRaises(
|
|
||||||
AssertionError, DirContains, filenames=[], matcher=Contains('a'))
|
|
||||||
|
|
||||||
def test_does_not_contain_files(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
self.touch(os.path.join(tempdir, 'foo'))
|
|
||||||
mismatch = DirContains(['bar', 'foo']).match(tempdir)
|
|
||||||
self.assertThat(
|
|
||||||
Equals(['bar', 'foo']).match(['foo']).describe(),
|
|
||||||
Equals(mismatch.describe()))
|
|
||||||
|
|
||||||
|
|
||||||
class TestFileContains(TestCase, PathHelpers):
|
|
||||||
|
|
||||||
def test_not_exists(self):
|
|
||||||
doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
|
|
||||||
mismatch = FileContains('').match(doesntexist)
|
|
||||||
self.assertThat(
|
|
||||||
PathExists().match(doesntexist).describe(),
|
|
||||||
Equals(mismatch.describe()))
|
|
||||||
|
|
||||||
def test_contains(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
filename = os.path.join(tempdir, 'foo')
|
|
||||||
self.create_file(filename, 'Hello World!')
|
|
||||||
self.assertThat(filename, FileContains('Hello World!'))
|
|
||||||
|
|
||||||
def test_matcher(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
filename = os.path.join(tempdir, 'foo')
|
|
||||||
self.create_file(filename, 'Hello World!')
|
|
||||||
self.assertThat(
|
|
||||||
filename, FileContains(matcher=DocTestMatches('Hello World!')))
|
|
||||||
|
|
||||||
def test_neither_specified(self):
|
|
||||||
self.assertRaises(AssertionError, FileContains)
|
|
||||||
|
|
||||||
def test_both_specified(self):
|
|
||||||
self.assertRaises(
|
|
||||||
AssertionError, FileContains, contents=[], matcher=Contains('a'))
|
|
||||||
|
|
||||||
def test_does_not_contain(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
filename = os.path.join(tempdir, 'foo')
|
|
||||||
self.create_file(filename, 'Goodbye Cruel World!')
|
|
||||||
mismatch = FileContains('Hello World!').match(filename)
|
|
||||||
self.assertThat(
|
|
||||||
Equals('Hello World!').match('Goodbye Cruel World!').describe(),
|
|
||||||
Equals(mismatch.describe()))
|
|
||||||
|
|
||||||
|
|
||||||
def is_even(x):
|
def is_even(x):
|
||||||
return x % 2 == 0
|
return x % 2 == 0
|
||||||
|
|
||||||
@@ -1005,69 +840,6 @@ class TestMatchesPredicate(TestCase, TestMatchersInterface):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class TestTarballContains(TestCase, PathHelpers):
|
|
||||||
|
|
||||||
def test_match(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
in_temp_dir = lambda x: os.path.join(tempdir, x)
|
|
||||||
self.touch(in_temp_dir('a'))
|
|
||||||
self.touch(in_temp_dir('b'))
|
|
||||||
tarball = tarfile.open(in_temp_dir('foo.tar.gz'), 'w')
|
|
||||||
tarball.add(in_temp_dir('a'), 'a')
|
|
||||||
tarball.add(in_temp_dir('b'), 'b')
|
|
||||||
tarball.close()
|
|
||||||
self.assertThat(
|
|
||||||
in_temp_dir('foo.tar.gz'), TarballContains(['b', 'a']))
|
|
||||||
|
|
||||||
def test_mismatch(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
in_temp_dir = lambda x: os.path.join(tempdir, x)
|
|
||||||
self.touch(in_temp_dir('a'))
|
|
||||||
self.touch(in_temp_dir('b'))
|
|
||||||
tarball = tarfile.open(in_temp_dir('foo.tar.gz'), 'w')
|
|
||||||
tarball.add(in_temp_dir('a'), 'a')
|
|
||||||
tarball.add(in_temp_dir('b'), 'b')
|
|
||||||
tarball.close()
|
|
||||||
mismatch = TarballContains(['d', 'c']).match(in_temp_dir('foo.tar.gz'))
|
|
||||||
self.assertEqual(
|
|
||||||
mismatch.describe(),
|
|
||||||
Equals(['c', 'd']).match(['a', 'b']).describe())
|
|
||||||
|
|
||||||
|
|
||||||
class TestSamePath(TestCase, PathHelpers):
|
|
||||||
|
|
||||||
def test_same_string(self):
|
|
||||||
self.assertThat('foo', SamePath('foo'))
|
|
||||||
|
|
||||||
def test_relative_and_absolute(self):
|
|
||||||
path = 'foo'
|
|
||||||
abspath = os.path.abspath(path)
|
|
||||||
self.assertThat(path, SamePath(abspath))
|
|
||||||
self.assertThat(abspath, SamePath(path))
|
|
||||||
|
|
||||||
def test_real_path(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
source = os.path.join(tempdir, 'source')
|
|
||||||
self.touch(source)
|
|
||||||
target = os.path.join(tempdir, 'target')
|
|
||||||
try:
|
|
||||||
os.symlink(source, target)
|
|
||||||
except (AttributeError, NotImplementedError):
|
|
||||||
self.skip("No symlink support")
|
|
||||||
self.assertThat(source, SamePath(target))
|
|
||||||
self.assertThat(target, SamePath(source))
|
|
||||||
|
|
||||||
|
|
||||||
class TestHasPermissions(TestCase, PathHelpers):
|
|
||||||
|
|
||||||
def test_match(self):
|
|
||||||
tempdir = self.mkdtemp()
|
|
||||||
filename = os.path.join(tempdir, 'filename')
|
|
||||||
self.touch(filename)
|
|
||||||
permissions = oct(os.stat(filename).st_mode)[-4:]
|
|
||||||
self.assertThat(filename, HasPermissions(permissions))
|
|
||||||
|
|
||||||
|
|
||||||
class TestSubDictOf(TestCase, TestMatchersInterface):
|
class TestSubDictOf(TestCase, TestMatchersInterface):
|
||||||
|
|
||||||
matches_matcher = _SubDictOf({'foo': 'bar', 'baz': 'qux'})
|
matches_matcher = _SubDictOf({'foo': 'bar', 'baz': 'qux'})
|
||||||
|
|||||||
243
testtools/tests/matchers/test_filesystem.py
Normal file
243
testtools/tests/matchers/test_filesystem.py
Normal file
@@ -0,0 +1,243 @@
|
|||||||
|
# Copyright (c) 2008-2012 testtools developers. See LICENSE for details.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import tarfile
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from testtools import TestCase
|
||||||
|
from testtools.matchers import (
|
||||||
|
Contains,
|
||||||
|
DocTestMatches,
|
||||||
|
Equals,
|
||||||
|
)
|
||||||
|
from testtools.matchers._filesystem import (
|
||||||
|
DirContains,
|
||||||
|
DirExists,
|
||||||
|
FileContains,
|
||||||
|
FileExists,
|
||||||
|
HasPermissions,
|
||||||
|
PathExists,
|
||||||
|
SamePath,
|
||||||
|
TarballContains,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class PathHelpers(object):
|
||||||
|
|
||||||
|
def mkdtemp(self):
|
||||||
|
directory = tempfile.mkdtemp()
|
||||||
|
self.addCleanup(shutil.rmtree, directory)
|
||||||
|
return directory
|
||||||
|
|
||||||
|
def create_file(self, filename, contents=''):
|
||||||
|
fp = open(filename, 'w')
|
||||||
|
try:
|
||||||
|
fp.write(contents)
|
||||||
|
finally:
|
||||||
|
fp.close()
|
||||||
|
|
||||||
|
def touch(self, filename):
|
||||||
|
return self.create_file(filename)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPathExists(TestCase, PathHelpers):
|
||||||
|
|
||||||
|
def test_exists(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
self.assertThat(tempdir, PathExists())
|
||||||
|
|
||||||
|
def test_not_exists(self):
|
||||||
|
doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
|
||||||
|
mismatch = PathExists().match(doesntexist)
|
||||||
|
self.assertThat(
|
||||||
|
"%s does not exist." % doesntexist, Equals(mismatch.describe()))
|
||||||
|
|
||||||
|
|
||||||
|
class TestDirExists(TestCase, PathHelpers):
|
||||||
|
|
||||||
|
def test_exists(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
self.assertThat(tempdir, DirExists())
|
||||||
|
|
||||||
|
def test_not_exists(self):
|
||||||
|
doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
|
||||||
|
mismatch = DirExists().match(doesntexist)
|
||||||
|
self.assertThat(
|
||||||
|
PathExists().match(doesntexist).describe(),
|
||||||
|
Equals(mismatch.describe()))
|
||||||
|
|
||||||
|
def test_not_a_directory(self):
|
||||||
|
filename = os.path.join(self.mkdtemp(), 'foo')
|
||||||
|
self.touch(filename)
|
||||||
|
mismatch = DirExists().match(filename)
|
||||||
|
self.assertThat(
|
||||||
|
"%s is not a directory." % filename, Equals(mismatch.describe()))
|
||||||
|
|
||||||
|
|
||||||
|
class TestFileExists(TestCase, PathHelpers):
|
||||||
|
|
||||||
|
def test_exists(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
filename = os.path.join(tempdir, 'filename')
|
||||||
|
self.touch(filename)
|
||||||
|
self.assertThat(filename, FileExists())
|
||||||
|
|
||||||
|
def test_not_exists(self):
|
||||||
|
doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
|
||||||
|
mismatch = FileExists().match(doesntexist)
|
||||||
|
self.assertThat(
|
||||||
|
PathExists().match(doesntexist).describe(),
|
||||||
|
Equals(mismatch.describe()))
|
||||||
|
|
||||||
|
def test_not_a_file(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
mismatch = FileExists().match(tempdir)
|
||||||
|
self.assertThat(
|
||||||
|
"%s is not a file." % tempdir, Equals(mismatch.describe()))
|
||||||
|
|
||||||
|
|
||||||
|
class TestDirContains(TestCase, PathHelpers):
|
||||||
|
|
||||||
|
def test_empty(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
self.assertThat(tempdir, DirContains([]))
|
||||||
|
|
||||||
|
def test_not_exists(self):
|
||||||
|
doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
|
||||||
|
mismatch = DirContains([]).match(doesntexist)
|
||||||
|
self.assertThat(
|
||||||
|
PathExists().match(doesntexist).describe(),
|
||||||
|
Equals(mismatch.describe()))
|
||||||
|
|
||||||
|
def test_contains_files(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
self.touch(os.path.join(tempdir, 'foo'))
|
||||||
|
self.touch(os.path.join(tempdir, 'bar'))
|
||||||
|
self.assertThat(tempdir, DirContains(['bar', 'foo']))
|
||||||
|
|
||||||
|
def test_matcher(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
self.touch(os.path.join(tempdir, 'foo'))
|
||||||
|
self.touch(os.path.join(tempdir, 'bar'))
|
||||||
|
self.assertThat(tempdir, DirContains(matcher=Contains('bar')))
|
||||||
|
|
||||||
|
def test_neither_specified(self):
|
||||||
|
self.assertRaises(AssertionError, DirContains)
|
||||||
|
|
||||||
|
def test_both_specified(self):
|
||||||
|
self.assertRaises(
|
||||||
|
AssertionError, DirContains, filenames=[], matcher=Contains('a'))
|
||||||
|
|
||||||
|
def test_does_not_contain_files(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
self.touch(os.path.join(tempdir, 'foo'))
|
||||||
|
mismatch = DirContains(['bar', 'foo']).match(tempdir)
|
||||||
|
self.assertThat(
|
||||||
|
Equals(['bar', 'foo']).match(['foo']).describe(),
|
||||||
|
Equals(mismatch.describe()))
|
||||||
|
|
||||||
|
|
||||||
|
class TestFileContains(TestCase, PathHelpers):
|
||||||
|
|
||||||
|
def test_not_exists(self):
|
||||||
|
doesntexist = os.path.join(self.mkdtemp(), 'doesntexist')
|
||||||
|
mismatch = FileContains('').match(doesntexist)
|
||||||
|
self.assertThat(
|
||||||
|
PathExists().match(doesntexist).describe(),
|
||||||
|
Equals(mismatch.describe()))
|
||||||
|
|
||||||
|
def test_contains(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
filename = os.path.join(tempdir, 'foo')
|
||||||
|
self.create_file(filename, 'Hello World!')
|
||||||
|
self.assertThat(filename, FileContains('Hello World!'))
|
||||||
|
|
||||||
|
def test_matcher(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
filename = os.path.join(tempdir, 'foo')
|
||||||
|
self.create_file(filename, 'Hello World!')
|
||||||
|
self.assertThat(
|
||||||
|
filename, FileContains(matcher=DocTestMatches('Hello World!')))
|
||||||
|
|
||||||
|
def test_neither_specified(self):
|
||||||
|
self.assertRaises(AssertionError, FileContains)
|
||||||
|
|
||||||
|
def test_both_specified(self):
|
||||||
|
self.assertRaises(
|
||||||
|
AssertionError, FileContains, contents=[], matcher=Contains('a'))
|
||||||
|
|
||||||
|
def test_does_not_contain(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
filename = os.path.join(tempdir, 'foo')
|
||||||
|
self.create_file(filename, 'Goodbye Cruel World!')
|
||||||
|
mismatch = FileContains('Hello World!').match(filename)
|
||||||
|
self.assertThat(
|
||||||
|
Equals('Hello World!').match('Goodbye Cruel World!').describe(),
|
||||||
|
Equals(mismatch.describe()))
|
||||||
|
class TestTarballContains(TestCase, PathHelpers):
|
||||||
|
|
||||||
|
def test_match(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
in_temp_dir = lambda x: os.path.join(tempdir, x)
|
||||||
|
self.touch(in_temp_dir('a'))
|
||||||
|
self.touch(in_temp_dir('b'))
|
||||||
|
tarball = tarfile.open(in_temp_dir('foo.tar.gz'), 'w')
|
||||||
|
tarball.add(in_temp_dir('a'), 'a')
|
||||||
|
tarball.add(in_temp_dir('b'), 'b')
|
||||||
|
tarball.close()
|
||||||
|
self.assertThat(
|
||||||
|
in_temp_dir('foo.tar.gz'), TarballContains(['b', 'a']))
|
||||||
|
|
||||||
|
def test_mismatch(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
in_temp_dir = lambda x: os.path.join(tempdir, x)
|
||||||
|
self.touch(in_temp_dir('a'))
|
||||||
|
self.touch(in_temp_dir('b'))
|
||||||
|
tarball = tarfile.open(in_temp_dir('foo.tar.gz'), 'w')
|
||||||
|
tarball.add(in_temp_dir('a'), 'a')
|
||||||
|
tarball.add(in_temp_dir('b'), 'b')
|
||||||
|
tarball.close()
|
||||||
|
mismatch = TarballContains(['d', 'c']).match(in_temp_dir('foo.tar.gz'))
|
||||||
|
self.assertEqual(
|
||||||
|
mismatch.describe(),
|
||||||
|
Equals(['c', 'd']).match(['a', 'b']).describe())
|
||||||
|
|
||||||
|
|
||||||
|
class TestSamePath(TestCase, PathHelpers):
|
||||||
|
|
||||||
|
def test_same_string(self):
|
||||||
|
self.assertThat('foo', SamePath('foo'))
|
||||||
|
|
||||||
|
def test_relative_and_absolute(self):
|
||||||
|
path = 'foo'
|
||||||
|
abspath = os.path.abspath(path)
|
||||||
|
self.assertThat(path, SamePath(abspath))
|
||||||
|
self.assertThat(abspath, SamePath(path))
|
||||||
|
|
||||||
|
def test_real_path(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
source = os.path.join(tempdir, 'source')
|
||||||
|
self.touch(source)
|
||||||
|
target = os.path.join(tempdir, 'target')
|
||||||
|
try:
|
||||||
|
os.symlink(source, target)
|
||||||
|
except (AttributeError, NotImplementedError):
|
||||||
|
self.skip("No symlink support")
|
||||||
|
self.assertThat(source, SamePath(target))
|
||||||
|
self.assertThat(target, SamePath(source))
|
||||||
|
|
||||||
|
|
||||||
|
class TestHasPermissions(TestCase, PathHelpers):
|
||||||
|
|
||||||
|
def test_match(self):
|
||||||
|
tempdir = self.mkdtemp()
|
||||||
|
filename = os.path.join(tempdir, 'filename')
|
||||||
|
self.touch(filename)
|
||||||
|
permissions = oct(os.stat(filename).st_mode)[-4:]
|
||||||
|
self.assertThat(filename, HasPermissions(permissions))
|
||||||
|
|
||||||
|
|
||||||
|
def test_suite():
|
||||||
|
from unittest import TestLoader
|
||||||
|
return TestLoader().loadTestsFromName(__name__)
|
||||||
Reference in New Issue
Block a user