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.
29 class subst_pathTestCase(unittest
.TestCase
):
31 def setUp(self
) -> None:
33 class FakeEnvironment
:
34 def __init__(self
, **kw
) -> None:
36 def subst(self
, s
, target
=None, source
=None, conv
=lambda x
: x
):
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
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
73 def __str__(self
) -> str:
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
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'],
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
163 SCons
.PathList
.PathListCache
164 except AttributeError:
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__":
191 # indent-tabs-mode:nil
193 # vim: set expandtab tabstop=4 shiftwidth=4: