|
3 | 3 | from string import Template |
4 | 4 | import types |
5 | 5 | from test.support import cpython_only |
6 | | -from test.support import os_helper |
7 | 6 | from test.support.import_helper import ensure_lazy_imports |
8 | 7 |
|
9 | 8 |
|
@@ -41,97 +40,6 @@ def test_capwords(self): |
41 | 40 | self.assertEqual(string.capwords('\taBc\tDeF\t'), 'Abc Def') |
42 | 41 | self.assertEqual(string.capwords('\taBc\tDeF\t', '\t'), '\tAbc\tDef\t') |
43 | 42 |
|
44 | | - def test_commonprefix(self): |
45 | | - self.assertEqual( |
46 | | - string.commonprefix([]), |
47 | | - "" |
48 | | - ) |
49 | | - self.assertEqual( |
50 | | - string.commonprefix(["a", "b"]), |
51 | | - "" |
52 | | - ) |
53 | | - self.assertEqual( |
54 | | - string.commonprefix(["/home/swenson/spam", "/home/swen/spam"]), |
55 | | - "/home/swen" |
56 | | - ) |
57 | | - self.assertEqual( |
58 | | - string.commonprefix(["/home/swen/spam", "/home/swen/eggs"]), |
59 | | - "/home/swen/" |
60 | | - ) |
61 | | - self.assertEqual( |
62 | | - string.commonprefix(["/home/swen/spam", "/home/swen/spam"]), |
63 | | - "/home/swen/spam" |
64 | | - ) |
65 | | - self.assertEqual( |
66 | | - string.commonprefix(["home:swenson:spam", "home:swen:spam"]), |
67 | | - "home:swen" |
68 | | - ) |
69 | | - self.assertEqual( |
70 | | - string.commonprefix([":home:swen:spam", ":home:swen:eggs"]), |
71 | | - ":home:swen:" |
72 | | - ) |
73 | | - self.assertEqual( |
74 | | - string.commonprefix([":home:swen:spam", ":home:swen:spam"]), |
75 | | - ":home:swen:spam" |
76 | | - ) |
77 | | - |
78 | | - self.assertEqual( |
79 | | - string.commonprefix([b"/home/swenson/spam", b"/home/swen/spam"]), |
80 | | - b"/home/swen" |
81 | | - ) |
82 | | - self.assertEqual( |
83 | | - string.commonprefix([b"/home/swen/spam", b"/home/swen/eggs"]), |
84 | | - b"/home/swen/" |
85 | | - ) |
86 | | - self.assertEqual( |
87 | | - string.commonprefix([b"/home/swen/spam", b"/home/swen/spam"]), |
88 | | - b"/home/swen/spam" |
89 | | - ) |
90 | | - self.assertEqual( |
91 | | - string.commonprefix([b"home:swenson:spam", b"home:swen:spam"]), |
92 | | - b"home:swen" |
93 | | - ) |
94 | | - self.assertEqual( |
95 | | - string.commonprefix([b":home:swen:spam", b":home:swen:eggs"]), |
96 | | - b":home:swen:" |
97 | | - ) |
98 | | - self.assertEqual( |
99 | | - string.commonprefix([b":home:swen:spam", b":home:swen:spam"]), |
100 | | - b":home:swen:spam" |
101 | | - ) |
102 | | - |
103 | | - testlist = ['', 'abc', 'Xbcd', 'Xb', 'XY', 'abcd', |
104 | | - 'aXc', 'abd', 'ab', 'aX', 'abcX'] |
105 | | - for s1 in testlist: |
106 | | - for s2 in testlist: |
107 | | - p = string.commonprefix([s1, s2]) |
108 | | - self.assertStartsWith(s1, p) |
109 | | - self.assertStartsWith(s2, p) |
110 | | - if s1 != s2: |
111 | | - n = len(p) |
112 | | - self.assertNotEqual(s1[n:n+1], s2[n:n+1]) |
113 | | - |
114 | | - def test_commonprefix_paths(self): |
115 | | - # Test backwards-compatibility with os.path.commonprefix() |
116 | | - # This function must handle PathLike objects. |
117 | | - file_name = os_helper.TESTFN |
118 | | - file_path = os_helper.FakePath(file_name) |
119 | | - self.assertEqual(string.commonprefix([file_path, file_name]), |
120 | | - file_name) |
121 | | - |
122 | | - def test_commonprefix_sequence_of_str(self): |
123 | | - # Test backwards-compatibility with os.path.commonprefix() |
124 | | - # This function must handle lists and tuples of strings. |
125 | | - for type_ in (tuple, list): |
126 | | - seq1 = type_(["abc", "de", "fgh"]) |
127 | | - seq2 = type_(["abc", "def", "gh"]) |
128 | | - self.assertEqual(string.commonprefix([seq1, seq2]), |
129 | | - type_(["abc"])) |
130 | | - |
131 | | - seq1 = type_(["ab"]) |
132 | | - seq2 = type_(["ac"]) |
133 | | - self.assertEqual(string.commonprefix([seq1, seq2]), type_([])) |
134 | | - |
135 | 43 | def test_basic_formatter(self): |
136 | 44 | fmt = string.Formatter() |
137 | 45 | self.assertEqual(fmt.format("foo"), "foo") |
|
0 commit comments