forked from pantsbuild/pants
/
run_setup_py_test.py
735 lines (672 loc) · 26.4 KB
/
run_setup_py_test.py
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# Copyright 2019 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
import json
import textwrap
from typing import Iterable, Type
import pytest
from pants.backend.python.python_artifact import PythonArtifact
from pants.backend.python.rules.run_setup_py import (
AmbiguousOwnerError,
AncestorInitPyFiles,
DependencyOwner,
ExportedTarget,
ExportedTargetRequirements,
InvalidEntryPoint,
InvalidSetupPyArgs,
NoOwnerError,
OwnedDependencies,
OwnedDependency,
SetupPyChroot,
SetupPyChrootRequest,
SetupPySources,
SetupPySourcesRequest,
generate_chroot,
get_ancestor_init_py,
get_exporting_owner,
get_owned_dependencies,
get_requirements,
get_sources,
validate_args,
)
from pants.backend.python.target_types import PythonBinary, PythonLibrary, PythonRequirementLibrary
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.core.target_types import Resources
from pants.core.util_rules.determine_source_files import rules as determine_source_files_rules
from pants.core.util_rules.strip_source_roots import rules as strip_source_roots_rules
from pants.engine.addresses import Address
from pants.engine.fs import Snapshot
from pants.engine.internals.scheduler import ExecutionError
from pants.engine.rules import RootRule
from pants.engine.selectors import Params
from pants.engine.target import Target, Targets, WrappedTarget
from pants.python.python_requirement import PythonRequirement
from pants.source.source_root import SourceRootConfig
from pants.testutil.option.util import create_options_bootstrapper
from pants.testutil.subsystem.util import init_subsystem
from pants.testutil.test_base import TestBase
_namespace_decl = "__import__('pkg_resources').declare_namespace(__name__)"
class TestSetupPyBase(TestBase):
@classmethod
def alias_groups(cls) -> BuildFileAliases:
return BuildFileAliases(
objects={"python_requirement": PythonRequirement, "setup_py": PythonArtifact}
)
@classmethod
def target_types(cls):
return [PythonBinary, PythonLibrary, PythonRequirementLibrary, Resources]
def tgt(self, addr: str) -> Target:
return self.request_single_product(WrappedTarget, Params(Address.parse(addr))).target
def init_source_root():
init_subsystem(SourceRootConfig, options={"source": {"root_patterns": ["src/python"]}})
class TestGenerateChroot(TestSetupPyBase):
@classmethod
def rules(cls):
return super().rules() + [
generate_chroot,
get_sources,
get_requirements,
get_ancestor_init_py,
get_owned_dependencies,
get_exporting_owner,
RootRule(SetupPyChrootRequest),
*determine_source_files_rules(),
*strip_source_roots_rules(),
]
def assert_chroot(self, expected_files, expected_setup_kwargs, addr):
chroot = self.request_single_product(
SetupPyChroot,
Params(
SetupPyChrootRequest(ExportedTarget(self.tgt(addr)), py2=False),
create_options_bootstrapper(args=["--source-root-patterns=src/python"]),
),
)
snapshot = self.request_single_product(Snapshot, Params(chroot.digest))
assert sorted(expected_files) == sorted(snapshot.files)
kwargs = json.loads(chroot.setup_keywords_json)
assert expected_setup_kwargs == kwargs
def assert_error(self, addr: str, exc_cls: Type[Exception]):
with pytest.raises(ExecutionError) as excinfo:
self.request_single_product(
SetupPyChroot,
Params(
SetupPyChrootRequest(ExportedTarget(self.tgt(addr)), py2=False),
create_options_bootstrapper(args=["--source-root-patterns=src/python"]),
),
)
ex = excinfo.value
assert len(ex.wrapped_exceptions) == 1
assert type(ex.wrapped_exceptions[0]) == exc_cls
def test_generate_chroot(self) -> None:
init_source_root()
self.create_file(
"src/python/foo/bar/baz/BUILD",
"python_library(provides=setup_py(name='baz', version='1.1.1'))",
)
self.create_file("src/python/foo/bar/baz/baz.py", "")
self.create_file(
"src/python/foo/qux/BUILD",
textwrap.dedent(
"""
python_library()
python_binary(name="bin", entry_point="foo.qux.bin")
"""
),
)
self.create_file("src/python/foo/qux/__init__.py", "")
self.create_file("src/python/foo/qux/qux.py", "")
self.create_file("src/python/foo/resources/BUILD", 'resources(sources=["js/code.js"])')
self.create_file("src/python/foo/resources/js/code.js", "")
self.create_file(
"src/python/foo/BUILD",
textwrap.dedent(
"""
python_library(
dependencies=[
'src/python/foo/bar/baz',
'src/python/foo/qux',
'src/python/foo/resources',
],
provides=setup_py(
name='foo', version='1.2.3'
).with_binaries(
foo_main='src/python/foo/qux:bin'
)
)
"""
),
)
self.create_file("src/python/foo/__init__.py", _namespace_decl)
self.create_file("src/python/foo/foo.py", "")
self.assert_chroot(
[
"src/foo/qux/__init__.py",
"src/foo/qux/qux.py",
"src/foo/resources/js/code.js",
"src/foo/__init__.py",
"src/foo/foo.py",
"setup.py",
"MANIFEST.in",
],
{
"name": "foo",
"version": "1.2.3",
"package_dir": {"": "src"},
"packages": ["foo", "foo.qux", "foo.resources.js"],
"namespace_packages": ["foo"],
"package_data": {"foo": ["resources/js/code.js"]},
"install_requires": ["baz==1.1.1"],
"entry_points": {"console_scripts": ["foo_main=foo.qux.bin"]},
},
"src/python/foo",
)
def test_invalid_binary(self) -> None:
init_source_root()
self.create_file(
"src/python/invalid_binary/BUILD",
textwrap.dedent(
"""
python_library(name='not_a_binary', sources=[])
python_binary(name='no_entrypoint')
python_library(
name='invalid_bin1',
sources=[],
provides=setup_py(
name='invalid_bin1', version='1.1.1'
).with_binaries(foo=':not_a_binary')
)
python_library(
name='invalid_bin2',
sources=[],
provides=setup_py(
name='invalid_bin2', version='1.1.1'
).with_binaries(foo=':no_entrypoint')
)
"""
),
)
self.assert_error("src/python/invalid_binary:invalid_bin1", InvalidEntryPoint)
self.assert_error("src/python/invalid_binary:invalid_bin2", InvalidEntryPoint)
class TestGetSources(TestSetupPyBase):
@classmethod
def rules(cls):
return super().rules() + [
get_sources,
get_ancestor_init_py,
RootRule(SetupPySourcesRequest),
RootRule(SourceRootConfig),
*determine_source_files_rules(),
*strip_source_roots_rules(),
]
def assert_sources(
self,
expected_files,
expected_packages,
expected_namespace_packages,
expected_package_data,
addrs,
):
srcs = self.request_single_product(
SetupPySources,
Params(
SetupPySourcesRequest(Targets([self.tgt(addr) for addr in addrs]), py2=False),
SourceRootConfig.global_instance(),
),
)
chroot_snapshot = self.request_single_product(Snapshot, Params(srcs.digest))
assert sorted(expected_files) == sorted(chroot_snapshot.files)
assert sorted(expected_packages) == sorted(srcs.packages)
assert sorted(expected_namespace_packages) == sorted(srcs.namespace_packages)
assert expected_package_data == dict(srcs.package_data)
def test_get_sources(self) -> None:
init_source_root()
self.create_file(
"src/python/foo/bar/baz/BUILD",
textwrap.dedent(
"""
python_library(name='baz1', sources=['baz1.py'])
python_library(name='baz2', sources=['baz2.py'])
"""
),
)
self.create_file("src/python/foo/bar/baz/baz1.py", "")
self.create_file("src/python/foo/bar/baz/baz2.py", "")
self.create_file("src/python/foo/bar/__init__.py", _namespace_decl)
self.create_file("src/python/foo/qux/BUILD", "python_library()")
self.create_file("src/python/foo/qux/__init__.py", "")
self.create_file("src/python/foo/qux/qux.py", "")
self.create_file("src/python/foo/resources/BUILD", 'resources(sources=["js/code.js"])')
self.create_file("src/python/foo/resources/js/code.js", "")
self.create_file("src/python/foo/__init__.py", "")
self.assert_sources(
expected_files=["foo/bar/baz/baz1.py", "foo/bar/__init__.py", "foo/__init__.py"],
expected_packages=["foo", "foo.bar", "foo.bar.baz"],
expected_namespace_packages=["foo.bar"],
expected_package_data={},
addrs=["src/python/foo/bar/baz:baz1"],
)
self.assert_sources(
expected_files=["foo/bar/baz/baz2.py", "foo/bar/__init__.py", "foo/__init__.py"],
expected_packages=["foo", "foo.bar", "foo.bar.baz"],
expected_namespace_packages=["foo.bar"],
expected_package_data={},
addrs=["src/python/foo/bar/baz:baz2"],
)
self.assert_sources(
expected_files=["foo/qux/qux.py", "foo/qux/__init__.py", "foo/__init__.py"],
expected_packages=["foo", "foo.qux"],
expected_namespace_packages=[],
expected_package_data={},
addrs=["src/python/foo/qux"],
)
self.assert_sources(
expected_files=[
"foo/bar/baz/baz1.py",
"foo/bar/__init__.py",
"foo/qux/qux.py",
"foo/qux/__init__.py",
"foo/__init__.py",
"foo/resources/js/code.js",
],
expected_packages=["foo", "foo.bar", "foo.bar.baz", "foo.qux", "foo.resources.js"],
expected_namespace_packages=["foo.bar"],
expected_package_data={"foo": ("resources/js/code.js",)},
addrs=["src/python/foo/bar/baz:baz1", "src/python/foo/qux", "src/python/foo/resources"],
)
self.assert_sources(
expected_files=[
"foo/bar/baz/baz1.py",
"foo/bar/baz/baz2.py",
"foo/bar/__init__.py",
"foo/qux/qux.py",
"foo/qux/__init__.py",
"foo/__init__.py",
"foo/resources/js/code.js",
],
expected_packages=["foo", "foo.bar", "foo.bar.baz", "foo.qux", "foo.resources.js"],
expected_namespace_packages=["foo.bar"],
expected_package_data={"foo": ("resources/js/code.js",)},
addrs=[
"src/python/foo/bar/baz:baz1",
"src/python/foo/bar/baz:baz2",
"src/python/foo/qux",
"src/python/foo/resources",
],
)
class TestGetRequirements(TestSetupPyBase):
@classmethod
def rules(cls):
return super().rules() + [
get_requirements,
get_owned_dependencies,
get_exporting_owner,
RootRule(DependencyOwner),
]
def assert_requirements(self, expected_req_strs, addr):
reqs = self.request_single_product(
ExportedTargetRequirements,
Params(DependencyOwner(ExportedTarget(self.tgt(addr))), create_options_bootstrapper()),
)
assert sorted(expected_req_strs) == list(reqs)
def test_get_requirements(self) -> None:
self.create_file(
"3rdparty/BUILD",
textwrap.dedent(
"""
python_requirement_library(
name='ext1',
requirements=[python_requirement('ext1==1.22.333')],
)
python_requirement_library(
name='ext2',
requirements=[python_requirement('ext2==4.5.6')],
)
python_requirement_library(
name='ext3',
requirements=[python_requirement('ext3==0.0.1')],
)
"""
),
)
self.create_file(
"src/python/foo/bar/baz/BUILD",
"python_library(dependencies=['3rdparty:ext1'], sources=[])",
)
self.create_file(
"src/python/foo/bar/qux/BUILD",
"python_library(dependencies=['3rdparty:ext2', 'src/python/foo/bar/baz'], sources=[])",
)
self.create_file(
"src/python/foo/bar/BUILD",
textwrap.dedent(
"""
python_library(
sources=[],
dependencies=['src/python/foo/bar/baz', 'src/python/foo/bar/qux'],
provides=setup_py(name='bar', version='9.8.7'),
)
"""
),
)
self.create_file(
"src/python/foo/corge/BUILD",
textwrap.dedent(
"""
python_library(
sources=[],
dependencies=['3rdparty:ext3', 'src/python/foo/bar'],
provides=setup_py(name='corge', version='2.2.2'),
)
"""
),
)
self.assert_requirements(["ext1==1.22.333", "ext2==4.5.6"], "src/python/foo/bar")
self.assert_requirements(["ext3==0.0.1", "bar==9.8.7"], "src/python/foo/corge")
class TestGetAncestorInitPy(TestSetupPyBase):
@classmethod
def rules(cls):
return super().rules() + [
get_ancestor_init_py,
RootRule(Targets),
RootRule(SourceRootConfig),
*determine_source_files_rules(),
]
def assert_ancestor_init_py(
self, expected_init_pys: Iterable[str], addrs: Iterable[str]
) -> None:
ancestor_init_py_files = self.request_single_product(
AncestorInitPyFiles,
Params(
Targets([self.tgt(addr) for addr in addrs]), SourceRootConfig.global_instance(),
),
)
snapshots = [
self.request_single_product(Snapshot, Params(digest))
for digest in ancestor_init_py_files.digests
]
init_py_files_found = set([file for snapshot in snapshots for file in snapshot.files])
# NB: Doesn't include the root __init__.py or the missing src/python/foo/bar/__init__.py.
assert sorted(expected_init_pys) == sorted(init_py_files_found)
def test_get_ancestor_init_py(self) -> None:
init_source_root()
# NB: src/python/foo/bar/baz/qux/__init__.py is a target's source.
self.create_file("src/python/foo/bar/baz/qux/BUILD", "python_library()")
self.create_file("src/python/foo/bar/baz/qux/qux.py", "")
self.create_file("src/python/foo/bar/baz/qux/__init__.py", "")
self.create_file("src/python/foo/bar/baz/__init__.py", "")
# NB: No src/python/foo/bar/__init__.py.
# NB: src/python/foo/corge/__init__.py is not any target's source.
self.create_file("src/python/foo/corge/BUILD", 'python_library(sources=["corge.py"])')
self.create_file("src/python/foo/corge/corge.py", "")
self.create_file("src/python/foo/corge/__init__.py", "")
self.create_file("src/python/foo/__init__.py", "")
self.create_file("src/python/__init__.py", "")
self.create_file("src/python/foo/resources/BUILD", 'resources(sources=["style.css"])')
self.create_file("src/python/foo/resources/style.css", "")
# NB: A stray __init__.py in a resources-only dir.
self.create_file("src/python/foo/resources/__init__.py", "")
# NB: None of these should include the root src/python/__init__.py, the missing
# src/python/foo/bar/__init__.py, or the stray src/python/foo/resources/__init__.py.
self.assert_ancestor_init_py(
["foo/bar/baz/qux/__init__.py", "foo/bar/baz/__init__.py", "foo/__init__.py"],
["src/python/foo/bar/baz/qux"],
)
self.assert_ancestor_init_py([], ["src/python/foo/resources"])
self.assert_ancestor_init_py(
["foo/corge/__init__.py", "foo/__init__.py"],
["src/python/foo/corge", "src/python/foo/resources"],
)
self.assert_ancestor_init_py(
[
"foo/bar/baz/qux/__init__.py",
"foo/bar/baz/__init__.py",
"foo/corge/__init__.py",
"foo/__init__.py",
],
["src/python/foo/bar/baz/qux", "src/python/foo/corge"],
)
class TestGetOwnedDependencies(TestSetupPyBase):
@classmethod
def rules(cls):
return super().rules() + [
get_owned_dependencies,
get_exporting_owner,
RootRule(DependencyOwner),
]
def assert_owned(self, owned: Iterable[str], exported: str):
assert sorted(owned) == sorted(
od.target.address.reference()
for od in self.request_single_product(
OwnedDependencies,
Params(
DependencyOwner(ExportedTarget(self.tgt(exported))),
create_options_bootstrapper(),
),
)
)
def test_owned_dependencies(self) -> None:
self.create_file(
"src/python/foo/bar/baz/BUILD",
textwrap.dedent(
"""
python_library(name='baz1', sources=[])
python_library(name='baz2', sources=[])
"""
),
)
self.create_file(
"src/python/foo/bar/BUILD",
textwrap.dedent(
"""
python_library(
name='bar1',
sources=[],
dependencies=['src/python/foo/bar/baz:baz1'],
provides=setup_py(name='bar1', version='1.1.1'),
)
python_library(
name='bar2',
sources=[],
dependencies=[':bar-resources', 'src/python/foo/bar/baz:baz2'],
)
resources(name='bar-resources', sources=[])
"""
),
)
self.create_file(
"src/python/foo/BUILD",
textwrap.dedent(
"""
python_library(
name='foo',
sources=[],
dependencies=['src/python/foo/bar:bar1', 'src/python/foo/bar:bar2'],
provides=setup_py(name='foo', version='3.4.5'),
)
"""
),
)
self.assert_owned(
["src/python/foo/bar:bar1", "src/python/foo/bar/baz:baz1"], "src/python/foo/bar:bar1"
)
self.assert_owned(
[
"src/python/foo",
"src/python/foo/bar:bar2",
"src/python/foo/bar:bar-resources",
"src/python/foo/bar/baz:baz2",
],
"src/python/foo",
)
class TestGetExportingOwner(TestSetupPyBase):
@classmethod
def rules(cls):
return super().rules() + [
get_exporting_owner,
RootRule(OwnedDependency),
]
def assert_is_owner(self, owner: str, owned: str):
assert (
owner
== self.request_single_product(
ExportedTarget,
Params(OwnedDependency(self.tgt(owned)), create_options_bootstrapper()),
).target.address.reference()
)
def assert_error(self, owned: str, exc_cls: Type[Exception]):
with pytest.raises(ExecutionError) as excinfo:
self.request_single_product(
ExportedTarget,
Params(OwnedDependency(self.tgt(owned)), create_options_bootstrapper()),
)
ex = excinfo.value
assert len(ex.wrapped_exceptions) == 1
assert type(ex.wrapped_exceptions[0]) == exc_cls
def assert_no_owner(self, owned: str):
self.assert_error(owned, NoOwnerError)
def assert_ambiguous_owner(self, owned: str):
self.assert_error(owned, AmbiguousOwnerError)
def test_get_owner_simple(self) -> None:
self.create_file(
"src/python/foo/bar/baz/BUILD",
textwrap.dedent(
"""
python_library(name='baz1', sources=[])
python_library(name='baz2', sources=[])
"""
),
)
self.create_file(
"src/python/foo/bar/BUILD",
textwrap.dedent(
"""
python_library(
name='bar1',
sources=[],
dependencies=['src/python/foo/bar/baz:baz1'],
provides=setup_py(name='bar1', version='1.1.1'),
)
python_library(
name='bar2',
sources=[],
dependencies=[':bar-resources', 'src/python/foo/bar/baz:baz2'],
)
resources(name='bar-resources', sources=[])
"""
),
)
self.create_file(
"src/python/foo/BUILD",
textwrap.dedent(
"""
python_library(
name='foo1',
sources=[],
dependencies=['src/python/foo/bar/baz:baz2'],
provides=setup_py(name='foo1', version='0.1.2'),
)
python_library(name='foo2', sources=[])
python_library(
name='foo3',
sources=[],
dependencies=['src/python/foo/bar:bar2'],
provides=setup_py(name='foo3', version='3.4.5'),
)
"""
),
)
self.assert_is_owner("src/python/foo/bar:bar1", "src/python/foo/bar:bar1")
self.assert_is_owner("src/python/foo/bar:bar1", "src/python/foo/bar/baz:baz1")
self.assert_is_owner("src/python/foo:foo1", "src/python/foo:foo1")
self.assert_is_owner("src/python/foo:foo3", "src/python/foo:foo3")
self.assert_is_owner("src/python/foo:foo3", "src/python/foo/bar:bar2")
self.assert_is_owner("src/python/foo:foo3", "src/python/foo/bar:bar-resources")
self.assert_no_owner("src/python/foo:foo2")
self.assert_ambiguous_owner("src/python/foo/bar/baz:baz2")
def test_get_owner_siblings(self) -> None:
self.create_file(
"src/python/siblings/BUILD",
textwrap.dedent(
"""
python_library(name='sibling1', sources=[])
python_library(
name='sibling2',
sources=[],
dependencies=['src/python/siblings:sibling1'],
provides=setup_py(name='siblings', version='2.2.2'),
)
"""
),
)
self.assert_is_owner("src/python/siblings:sibling2", "src/python/siblings:sibling1")
self.assert_is_owner("src/python/siblings:sibling2", "src/python/siblings:sibling2")
def test_get_owner_not_an_ancestor(self) -> None:
self.create_file(
"src/python/notanancestor/aaa/BUILD",
textwrap.dedent(
"""
python_library(name='aaa', sources=[])
"""
),
)
self.create_file(
"src/python/notanancestor/bbb/BUILD",
textwrap.dedent(
"""
python_library(
name='bbb',
sources=[],
dependencies=['src/python/notanancestor/aaa'],
provides=setup_py(name='bbb', version='11.22.33'),
)
"""
),
)
self.assert_no_owner("src/python/notanancestor/aaa")
self.assert_is_owner("src/python/notanancestor/bbb", "src/python/notanancestor/bbb")
def test_get_owner_multiple_ancestor_generations(self) -> None:
self.create_file(
"src/python/aaa/bbb/ccc/BUILD",
textwrap.dedent(
"""
python_library(name='ccc', sources=[])
"""
),
)
self.create_file(
"src/python/aaa/bbb/BUILD",
textwrap.dedent(
"""
python_library(
name='bbb',
sources=[],
dependencies=['src/python/aaa/bbb/ccc'],
provides=setup_py(name='bbb', version='1.1.1'),
)
"""
),
)
self.create_file(
"src/python/aaa/BUILD",
textwrap.dedent(
"""
python_library(
name='aaa',
sources=[],
dependencies=['src/python/aaa/bbb/ccc'],
provides=setup_py(name='aaa', version='2.2.2'),
)
"""
),
)
self.assert_is_owner("src/python/aaa/bbb", "src/python/aaa/bbb/ccc")
self.assert_is_owner("src/python/aaa/bbb", "src/python/aaa/bbb")
self.assert_is_owner("src/python/aaa", "src/python/aaa")
def test_validate_args() -> None:
with pytest.raises(InvalidSetupPyArgs):
validate_args(("bdist_wheel", "upload"))
with pytest.raises(InvalidSetupPyArgs):
validate_args(("sdist", "-d", "new_distdir/"))
with pytest.raises(InvalidSetupPyArgs):
validate_args(("--dist-dir", "new_distdir/", "sdist"))
validate_args(("sdist",))
validate_args(("bdist_wheel", "--foo"))