-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathinternals.jl
382 lines (339 loc) · 14.1 KB
/
internals.jl
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
@testitem "PkgSpec" begin
include("setup.jl")
@test_throws Exception CondaPkg.PkgSpec("")
@test_throws Exception CondaPkg.PkgSpec("foo!")
@test_throws Exception CondaPkg.PkgSpec("foo", version = "foo")
spec = CondaPkg.PkgSpec(
" F...OO_-0 ",
version = " =1.2.3 ",
channel = " SOME_chaNNEL ",
)
@test spec.name == "f...oo_-0"
@test spec.version == "=1.2.3"
@test spec.channel == "SOME_chaNNEL"
end
@testitem "ChannelSpec" begin
include("setup.jl")
@test_throws Exception CondaPkg.ChannelSpec("")
spec = CondaPkg.ChannelSpec(" SOME_chaNNEL ")
@test spec.name == "SOME_chaNNEL"
end
@testitem "PipPkgSpec" begin
include("setup.jl")
@test_throws Exception CondaPkg.PipPkgSpec("")
@test_throws Exception CondaPkg.PipPkgSpec("foo!")
@test_throws Exception CondaPkg.PipPkgSpec("foo", version = "1.2")
spec = CondaPkg.PipPkgSpec(" F...OO_-0 ", version = " @./SOME/Path ")
@test spec.name == "f-oo-0"
@test spec.version == "@./SOME/Path"
end
@testitem "meta IO" begin
include("setup.jl")
specs = Any[
CondaPkg.PkgSpec("foo", version = "=1.2.3", channel = "bar"),
CondaPkg.ChannelSpec("fooo"),
CondaPkg.PipPkgSpec("foooo", version = "==2.3.4"),
]
for spec in specs
io = IOBuffer()
CondaPkg.write_meta(io, spec)
seekstart(io)
spec2 = CondaPkg.read_meta(io, typeof(spec))
@test spec == spec2
for k in propertynames(spec)
@test getproperty(spec, k) == getproperty(spec2, k)
end
end
end
@testitem "abspathurl" begin
include("setup.jl")
@test startswith(CondaPkg.abspathurl("foo"), "file://")
@test endswith(CondaPkg.abspathurl("foo"), "/foo")
if Sys.iswindows()
@test CondaPkg.abspathurl("D:\\Foo\\bar.TXT") == "file:///D:/Foo/bar.TXT"
else
@test CondaPkg.abspathurl("/Foo/bar.TXT") == "file:///Foo/bar.TXT"
end
end
@testitem "_resolve_merge_versions" begin
include("setup.jl")
@testset "$(case.v1) $(case.v2)" for case in [
(v1 = "1.2.3", v2 = "1.2.3", expected = "1.2.3, 1.2.3"),
(v1 = "1.2.3", v2 = "1.2.4", expected = "1.2.3, 1.2.4"),
(v1 = "1.2.3", v2 = ">=1.2,<2", expected = "1.2.3, >=1.2,<2"),
(v1 = ">=1.2,<2", v2 = ">=2.1,<3", expected = ">=1.2,<2, >=2.1,<3"),
(v1 = "1|2", v2 = "2|3", expected = "1, 2 | 1, 3 | 2, 2 | 2, 3"),
]
@test CondaPkg._resolve_merge_versions(case.v1, case.v2) == case.expected
end
end
@testitem "_compatible_libstdcxx_ng_version" begin
include("setup.jl")
@testset "$new_bound" for new_bound in [nothing, "", "foo"]
CondaPkg.STATE.test_preferences["libstdcxx_ng_version"] = new_bound
bound = CondaPkg._compatible_libstdcxx_ng_version()
if new_bound === nothing || new_bound == ""
if Sys.islinux()
if bound !== nothing
@test bound isa String
@test startswith(bound, ">=")
end
else
@test bound === nothing
end
else
@test bound == new_bound
end
end
end
@testitem "_compatible_openssl_version" begin
include("setup.jl")
@testset "$new_bound" for new_bound in [nothing, "", "foo"]
CondaPkg.STATE.test_preferences["openssl_version"] = new_bound
bound = CondaPkg._compatible_openssl_version()
if new_bound === nothing || new_bound == ""
if bound !== nothing
@test bound isa String
@test startswith(bound, ">=")
end
else
@test bound == new_bound
end
end
end
@testitem "checkpref" begin
include("setup.jl")
@testset "$(case.type) conversion" for case in [
# String conversions
(type = String, input = "hello", expected = "hello"),
# Int conversions
(type = Int, input = "42", expected = 42),
(type = Int, input = 42, expected = 42),
(type = Int, input = 42.0, expected = 42),
# Bool conversions
(type = Bool, input = "yes", expected = true),
(type = Bool, input = "true", expected = true),
(type = Bool, input = "no", expected = false),
(type = Bool, input = "false", expected = false),
(type = Bool, input = true, expected = true),
(type = Bool, input = false, expected = false),
# Vector{String} conversions
(type = Vector{String}, input = "", expected = String[]),
(type = Vector{String}, input = "a b c", expected = ["a", "b", "c"]),
(type = Vector{String}, input = ["a", "b", "c"], expected = ["a", "b", "c"]),
# Dict{String,String} conversions
(
type = Dict{String,String},
input = Dict("old" => "new", "foo" => "bar"),
expected = Dict("old" => "new", "foo" => "bar"),
),
(type = Dict{String,String}, input = "", expected = Dict{String,String}()),
(type = Dict{String,String}, input = "old->new", expected = Dict("old" => "new")),
(
type = Dict{String,String},
input = "old->new foo->bar",
expected = Dict("old" => "new", "foo" => "bar"),
),
(
type = Dict{String,String},
input = " old->new foo->bar ",
expected = Dict("old" => "new", "foo" => "bar"),
),
(type = Dict{String,String}, input = String[], expected = Dict{String,String}()),
(type = Dict{String,String}, input = ["old->new"], expected = Dict("old" => "new")),
(
type = Dict{String,String},
input = ["old->new", "foo->bar"],
expected = Dict("old" => "new", "foo" => "bar"),
),
]
result = CondaPkg.checkpref(case.type, case.input)
@test result isa case.type
@test result == case.expected
end
@testset "$(case.type) error" for case in [
(type = String, input = 42),
(type = String, input = :symbol),
(type = Bool, input = "invalid"),
(type = Int, input = "not a number"),
(type = Vector{String}, input = Any["a", :b, 42]),
]
@test_throws Exception CondaPkg.checkpref(case.type, case.input)
end
end
@testitem "_resolve_check_allowed_channels" begin
include("setup.jl")
# Test no allowed channels set
packages =
Dict("foo" => Dict("test.toml" => CondaPkg.PkgSpec("foo", channel = "bad-channel")))
channels = [CondaPkg.ChannelSpec("conda-forge")]
@test true ===
CondaPkg._resolve_check_allowed_channels(devnull, packages, channels, nothing)
# Test package with disallowed channel
allowed = Set(["conda-forge"])
packages =
Dict("foo" => Dict("test.toml" => CondaPkg.PkgSpec("foo", channel = "bad-channel")))
channels = [CondaPkg.ChannelSpec("conda-forge")]
@test_throws ErrorException(
"Package 'foo' in test.toml requires channel 'bad-channel' which is not in allowed channels list",
) CondaPkg._resolve_check_allowed_channels(devnull, packages, channels, allowed)
# Test global channel not allowed
allowed = Set(["conda-forge"])
packages = Dict("foo" => Dict("test.toml" => CondaPkg.PkgSpec("foo")))
channels = [CondaPkg.ChannelSpec("bad-channel")]
@test_throws ErrorException(
"The following channels are not in the allowed list: bad-channel",
) CondaPkg._resolve_check_allowed_channels(devnull, packages, channels, allowed)
# Test multiple disallowed global channels
allowed = Set(["conda-forge"])
packages = Dict("foo" => Dict("test.toml" => CondaPkg.PkgSpec("foo")))
channels = [CondaPkg.ChannelSpec("bad1"), CondaPkg.ChannelSpec("bad2")]
@test_throws ErrorException(
"The following channels are not in the allowed list: bad1, bad2",
) CondaPkg._resolve_check_allowed_channels(devnull, packages, channels, allowed)
# Test multiple allowed channels
allowed = Set(["conda-forge", "anaconda"])
packages = Dict(
"foo" => Dict("test.toml" => CondaPkg.PkgSpec("foo", channel = "conda-forge")),
"bar" => Dict("test.toml" => CondaPkg.PkgSpec("bar", channel = "anaconda")),
)
channels = [CondaPkg.ChannelSpec("conda-forge"), CondaPkg.ChannelSpec("anaconda")]
@test true ===
CondaPkg._resolve_check_allowed_channels(devnull, packages, channels, allowed)
end
@testitem "_resolve_order_channels!" begin
include("setup.jl")
# Test cases for channel ordering
cases = [
# Basic ordering: empty order uses defaults
(channels = ["b", "a", "c"], order = String[], expected = ["a", "b", "c"]),
# Basic ordering: explicit complete order
(channels = ["b", "a", "c"], order = ["c", "a", "b"], expected = ["c", "a", "b"]),
# Basic ordering: partial order
(channels = ["b", "a", "c"], order = ["c"], expected = ["c", "a", "b"]),
(channels = ["b", "a", "c"], order = ["b", "c"], expected = ["b", "c", "a"]),
# Ellipsis handling: in middle
(
channels = ["b", "a", "c", "d"],
order = ["c", "...", "a"],
expected = ["c", "b", "d", "a"],
),
# Ellipsis handling: at start
(
channels = ["b", "a", "c", "d"],
order = ["...", "a", "b"],
expected = ["c", "d", "a", "b"],
),
# Ellipsis handling: at end
(
channels = ["b", "a", "c", "d"],
order = ["d", "b", "..."],
expected = ["d", "b", "a", "c"],
),
# Special channels: conda-forge prioritized
(
channels = ["b", "conda-forge", "a"],
order = String[],
expected = ["conda-forge", "a", "b"],
),
# Special channels: all special channels present
(
channels = ["b", "conda-forge", "anaconda", "pkgs/main", "a"],
order = String[],
expected = ["conda-forge", "anaconda", "pkgs/main", "a", "b"],
),
# Special channels: override with explicit order
(
channels = ["conda-forge", "a", "b"],
order = ["...", "b", "conda-forge"],
expected = ["a", "b", "conda-forge"],
),
# Special channels: override with explicit order and all special channels present
(
channels = ["b", "conda-forge", "a", "pkgs/main", "anaconda"],
order = ["...", "b", "conda-forge"],
expected = ["anaconda", "pkgs/main", "a", "b", "conda-forge"],
),
# Deduplication: duplicate channels removed
(
channels = ["a", "a", "b", "b", "c"],
order = String[],
expected = ["a", "b", "c"],
),
# Deduplication: duplicate order entries ignored
(
channels = ["a", "b", "c"],
order = ["a", "a", "b", "b"],
expected = ["a", "b", "c"],
),
# Missing channels: order entries that don't exist ignored
(channels = ["a", "b"], order = ["c", "a", "d", "b"], expected = ["a", "b"]),
]
@testset "$(case.channels) $(case.order)" for case in cases
# Construct channel objects from strings
channels = [CondaPkg.ChannelSpec(name) for name in case.channels]
# Apply ordering in-place
CondaPkg._resolve_order_channels!(channels, case.order)
# Check result
@test [c.name for c in channels] == case.expected
end
end
@testitem "_resolve_map_channels!" begin
include("setup.jl")
# Test empty mapping does nothing
channels = [CondaPkg.ChannelSpec("conda-forge")]
packages = Dict("foo" => Dict("test.toml" => CondaPkg.PkgSpec("foo")))
mapping = Dict{String,String}()
CondaPkg._resolve_map_channels!(channels, packages, mapping)
@test channels[1].name == "conda-forge"
# Test global channel mapping
channels = [
CondaPkg.ChannelSpec("conda-forge"),
CondaPkg.ChannelSpec("old-channel"),
CondaPkg.ChannelSpec("other-channel"),
]
mapping = Dict("old-channel" => "new-channel", "other-channel" => "mapped-channel")
CondaPkg._resolve_map_channels!(channels, packages, mapping)
@test [c.name for c in channels] == ["conda-forge", "new-channel", "mapped-channel"]
# Test package-specific channel mapping
channels = [CondaPkg.ChannelSpec("conda-forge")]
packages = Dict(
"foo" => Dict(
"test1.toml" => CondaPkg.PkgSpec("foo", channel = "old-channel"),
"test2.toml" => CondaPkg.PkgSpec("foo", channel = "other-channel"),
),
"bar" =>
Dict("test.toml" => CondaPkg.PkgSpec("bar", channel = "unmapped-channel")),
)
mapping = Dict("old-channel" => "new-channel", "other-channel" => "mapped-channel")
CondaPkg._resolve_map_channels!(channels, packages, mapping)
@test packages["foo"]["test1.toml"].channel == "new-channel"
@test packages["foo"]["test2.toml"].channel == "mapped-channel"
@test packages["bar"]["test.toml"].channel == "unmapped-channel"
# Test both global and package-specific mapping together
channels = [CondaPkg.ChannelSpec("conda-forge"), CondaPkg.ChannelSpec("old-channel")]
packages =
Dict("foo" => Dict("test.toml" => CondaPkg.PkgSpec("foo", channel = "old-channel")))
mapping = Dict("old-channel" => "new-channel")
CondaPkg._resolve_map_channels!(channels, packages, mapping)
@test [c.name for c in channels] == ["conda-forge", "new-channel"]
@test packages["foo"]["test.toml"].channel == "new-channel"
# Test that other package properties are preserved
channels = [CondaPkg.ChannelSpec("old-channel")]
packages = Dict(
"foo" => Dict(
"test.toml" => CondaPkg.PkgSpec(
"foo",
version = "1.2.3",
channel = "old-channel",
build = "special",
),
),
)
mapping = Dict("old-channel" => "new-channel")
CondaPkg._resolve_map_channels!(channels, packages, mapping)
@test packages["foo"]["test.toml"].name == "foo"
@test packages["foo"]["test.toml"].version == "1.2.3"
@test packages["foo"]["test.toml"].channel == "new-channel"
@test packages["foo"]["test.toml"].build == "special"
end