added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / SCons / PathListTests.py
blob78fd1a4956317d4a7620d119638d81c49f4e8604
1 # MIT License
3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 import unittest
26 import SCons.PathList
29 class subst_pathTestCase(unittest.TestCase):
31 def setUp(self) -> None:
33 class FakeEnvironment:
34 def __init__(self, **kw) -> None:
35 self.kw = kw
36 def subst(self, s, target=None, source=None, conv=lambda x: x):
37 if s[0] == '$':
38 s = s[1:]
39 if s == 'target':
40 s = target
41 elif s == 'source':
42 s = source
43 else:
44 s = self.kw[s]
45 return s
47 self.env = FakeEnvironment(AAA = 'aaa', NULL = '')
48 from SCons.Environment import Environment
49 self.env = Environment(AAA = 'aaa', NULL = '')
51 def test_node(self) -> None:
52 """Test the subst_path() method on a Node
53 """
55 import SCons.Node
57 class A:
58 pass
60 n = SCons.Node.Node()
62 pl = SCons.PathList.PathList((n,))
64 result = pl.subst_path(self.env, 'y', 'z')
66 assert result == (n,), result
68 def test_object(self) -> None:
69 """Test the subst_path() method on a non-Node object
70 """
72 class A:
73 def __str__(self) -> str:
74 return '<object A>'
76 a = A()
78 pl = SCons.PathList.PathList((a,))
80 result = pl.subst_path(self.env, 'y', 'z')
82 assert result == ('<object A>',), result
84 def test_object_get(self) -> None:
85 """Test the subst_path() method on an object with a get() method
86 """
88 class B:
89 def get(self) -> str:
90 return 'b'
92 b = B()
94 pl = SCons.PathList.PathList((b,))
96 result = pl.subst_path(self.env, 'y', 'z')
98 assert result == ('b',), result
100 def test_string(self) -> None:
101 """Test the subst_path() method on a non-substitution string
104 self.env.subst = lambda s, target, source, conv: 'NOT THIS STRING'
106 pl = SCons.PathList.PathList(('x',))
108 result = pl.subst_path(self.env, 'y', 'z')
110 assert result == ('x',), result
112 def test_subst(self) -> None:
113 """Test the subst_path() method on substitution strings
116 pl = SCons.PathList.PathList(('$AAA', '$NULL'))
118 result = pl.subst_path(self.env, 'y', 'z')
120 assert result == ('aaa',), result
122 def test_list_of_lists(self) -> None:
123 """Test the subst_path() method on substitution of nested lists.
125 pl = SCons.PathList.PathList((['$AAA', '$AAA'], '$NULL'))
126 result = pl.subst_path(self.env, 'y', 'z')
127 assert result == ('aaa', 'aaa'), result
129 def test_subst_nested(self) -> None:
130 """Test the subst_path() method on nested substitution of strings.
132 self.env.Append(L1 = ['a', 'b'],
133 L2 = ['c', 'd'],
134 L3 = ['$L2'])
135 pl = SCons.PathList.PathList(['$L1'])
136 result = pl.subst_path(self.env, 'y', 'z')
137 assert result == ('a', 'b'), result
138 self.env.Append(L1 = ['$L2'])
139 pl = SCons.PathList.PathList(['$L1'])
140 result = pl.subst_path(self.env, 'y', 'z')
141 assert result == ('a', 'b', 'c', 'd'), result
142 self.env.Append(L1 = ['$L3'])
143 pl = SCons.PathList.PathList(['$L1'])
144 result = pl.subst_path(self.env, 'y', 'z')
145 assert result == ('a', 'b', 'c', 'd', 'c', 'd'), result
147 def test_another_env(self) -> None:
148 """Test the subst_path does lazy evaluation.
150 pl = SCons.PathList.PathList(('$AAA', '$NULL'))
151 result = pl.subst_path(self.env, 'y', 'z')
152 assert result == ('aaa',), result
153 e = self.env.Clone(AAA = 'bbb')
154 result = pl.subst_path(e, 'y', 'z')
155 assert result == ('bbb',), result
157 class PathListCacheTestCase(unittest.TestCase):
159 def test_no_PathListCache(self) -> None:
160 """Make sure the PathListCache class is not visible
162 try:
163 SCons.PathList.PathListCache
164 except AttributeError:
165 pass
166 else:
167 self.fail("Found PathListCache unexpectedly\n")
170 class PathListTestCase(unittest.TestCase):
172 def test_PathList(self) -> None:
173 """Test the PathList() entry point
176 x1 = SCons.PathList.PathList(('x',))
177 x2 = SCons.PathList.PathList(['x',])
179 assert x1 is x2, (x1, x2)
181 x3 = SCons.PathList.PathList('x')
183 assert x1 is not x3, (x1, x3)
186 if __name__ == "__main__":
187 unittest.main()
189 # Local Variables:
190 # tab-width:4
191 # indent-tabs-mode:nil
192 # End:
193 # vim: set expandtab tabstop=4 shiftwidth=4: