~ed.so/duplicity/reuse-passphrase-for-signing-fix

« back to all changes in this revision

Viewing changes to testing/pathtest.py

  • Committer: bescoto
  • Date: 2002-10-29 01:49:46 UTC
  • Revision ID: vcs-imports@canonical.com-20021029014946-3m4rmm5plom7pl6q
Initial checkin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
sys.path.insert(0, "../src")
 
3
import os, unittest
 
4
from path import *
 
5
 
 
6
class PathTest(unittest.TestCase):
 
7
        """Test basic path functions"""
 
8
        def test_deltree(self):
 
9
                """Test deleting a tree"""
 
10
                assert not os.system("rm -rf testfiles/output")
 
11
                assert not os.system("cp -a testfiles/deltree testfiles/output")
 
12
                p = Path("testfiles/output")
 
13
                assert p.isdir()
 
14
                p.deltree()
 
15
                assert not p.type, p.type
 
16
 
 
17
        def test_compare(self):
 
18
                """Test directory comparisons"""
 
19
                assert not os.system("cp -a testfiles/dir1 testfiles/output")
 
20
                assert Path("testfiles/dir1").compare_recursive(
 
21
                        Path("testfiles/output"), 1)
 
22
                assert not Path("testfiles/dir1").compare_recursive(
 
23
                        Path("testfiles/dir2"), 1)
 
24
 
 
25
        def test_quote(self):
 
26
                """Test path quoting"""
 
27
                p = Path("hello")
 
28
                assert p.quote() == '"hello"'
 
29
                assert p.quote("\\") == '"\\\\"', p.quote("\\")
 
30
                assert p.quote("$HELLO") == '"\\$HELLO"'
 
31
 
 
32
        def test_unquote(self):
 
33
                """Test path unquoting"""
 
34
                p = Path("foo") # just to provide unquote function
 
35
                def t(s):
 
36
                        """Run test on string s"""
 
37
                        quoted_version = p.quote(s)
 
38
                        unquoted = p.unquote(quoted_version)
 
39
                        assert unquoted == s, (unquoted, s)
 
40
 
 
41
                t("\\")
 
42
                t("$HELLO")
 
43
                t(" aoe aoe \\ \n`")
 
44
 
 
45
        def test_canonical(self):
 
46
                """Test getting canonical version of path"""
 
47
                c = Path(".").get_canonical()
 
48
                assert c == ".", c
 
49
 
 
50
                c = Path("//foo/bar/./").get_canonical()
 
51
                assert c == "/foo/bar", c
 
52
 
 
53
if __name__ == "__main__": unittest.main()