File: test_util_functions.py

package info (click to toggle)
mnemosyne 2.7.3%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 9,804 kB
  • sloc: python: 34,077; ansic: 837; xml: 625; makefile: 249; sh: 63
file content (69 lines) | stat: -rwxr-xr-x 2,257 bytes parent folder | download | duplicates (3)
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
67
68
69
#
# test_util_functions.py - Mike Appleby <mike@peacecorps.org.cv>
#

import os
import shutil

from mnemosyne.libmnemosyne.utils import *

class TestUtilFunctions(object):

    def test_numeric_string_cmp_1(self):
        s1 = "abc123"
        s2 = "abc1000"
        assert numeric_string_cmp_key(s1) < numeric_string_cmp_key(s2)

    def test_numeric_string_cmp_2(self):
        s1 = "Category 9"
        s2 = "Category 11"
        assert numeric_string_cmp_key(s1) < numeric_string_cmp_key(s2)

    def test_numeric_string_cmp_3(self):
        s1 = "3 blind mice"
        s2 = "3 blind pigs"
        assert numeric_string_cmp_key(s1) < numeric_string_cmp_key(s2)

    def test_numeric_string_cmp_3(self):
        s1 = "3 blind mice"
        s2 = "13 blind mice"
        assert numeric_string_cmp_key(s1) < numeric_string_cmp_key(s2)

    def test_numeric_string_cmp_4(self):
        s1 = "a"
        s2 = "b"
        assert numeric_string_cmp_key(s1) < numeric_string_cmp_key(s2)

    def test_numeric_string_cmp_5(self):
        s1 = "a123"
        s2 = "a123"
        assert numeric_string_cmp_key(s1) == numeric_string_cmp_key(s2)

    def test_numeric_string_cmp_6(self):
        s1 = "xyz 77"
        s2 = "xyz 42"
        assert numeric_string_cmp_key(s1) > numeric_string_cmp_key(s2)

    def test_contract_windows(self):
        assert contract_path("C:\\a\\b", "C:\\a") == "b"
        #assert contract_path("C:\\a\\b", "c:\\a") == "b"

    def test_mangle(self):
        for name in [mangle("1aa"), mangle("a!@#$% ^&*(){}{a"),
                     mangle("a\xac\\u1234\\u20ac\\U00008000")]:
            C = type(name, (self.__class__, ),
                 {"name": 1})

    def test_copy(self):
        assert copy_file_to_dir("/home/joe/test.py", "/home/joe") == "test.py"
        assert copy_file_to_dir("/home/joe/test.py", "/home/joe/") == "test.py"
        assert copy_file_to_dir("/home/joe/a/test.py", "/home/joe") == "a/test.py"
        assert copy_file_to_dir("/home/joe/a/test.py", "/home/joe/") == "a/test.py"

    def test_strip_tags(self):
        assert strip_tags("""<img = "">""") == ""

    def test_filesystem(self):
        is_filesystem_case_insensitive()