Skip to content

Commit

Permalink
Fix Python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Feb 6, 2024
1 parent ad4be74 commit c077db3
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 73 deletions.
14 changes: 7 additions & 7 deletions src/test/py/bazel/bzlmod/bazel_fetch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def testFetchAll(self):
self.RunBazel(['fetch', '--all'])
_, stdout, _ = self.RunBazel(['info', 'output_base'])
repos_fetched = os.listdir(stdout[0] + '/external')
self.assertIn('aaa~1.0', repos_fetched)
self.assertIn('bbb~1.0', repos_fetched)
self.assertIn('aaa~', repos_fetched)
self.assertIn('bbb~', repos_fetched)
self.assertIn('_main~ext~hello', repos_fetched)

def testFetchConfig(self):
Expand Down Expand Up @@ -141,7 +141,7 @@ def testFetchConfig(self):
self.RunBazel(['fetch', '--configure'])
_, stdout, _ = self.RunBazel(['info', 'output_base'])
repos_fetched = os.listdir(stdout[0] + '/external')
self.assertNotIn('aaa~1.0', repos_fetched)
self.assertNotIn('aaa~', repos_fetched)
self.assertNotIn('_main~ext~notConfig', repos_fetched)
self.assertIn('_main~ext~IamConfig', repos_fetched)

Expand Down Expand Up @@ -179,12 +179,12 @@ def testFetchRepo(self):
)
self.ScratchFile('BUILD')
# Test canonical/apparent repo names & multiple repos
self.RunBazel(['fetch', '--repo=@@bbb~1.0', '--repo=@my_repo'])
self.RunBazel(['fetch', '--repo=@@bbb~', '--repo=@my_repo'])
_, stdout, _ = self.RunBazel(['info', 'output_base'])
repos_fetched = os.listdir(stdout[0] + '/external')
self.assertIn('bbb~1.0', repos_fetched)
self.assertIn('ccc~1.0', repos_fetched)
self.assertNotIn('aaa~1.0', repos_fetched)
self.assertIn('bbb~', repos_fetched)
self.assertIn('ccc~', repos_fetched)
self.assertNotIn('aaa~', repos_fetched)

def testFetchInvalidRepo(self):
# Invalid repo name (not canonical or apparent)
Expand Down
20 changes: 10 additions & 10 deletions src/test/py/bazel/bzlmod/bazel_module_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,10 @@ def testNativePackageRelativeLabel(self):

_, _, stderr = self.RunBazel(['build', '@bar//quux:book'])
stderr = '\n'.join(stderr)
self.assertIn('1st: @@bar~override//quux:bleb', stderr)
self.assertIn('2nd: @@bar~override//bleb:bleb', stderr)
self.assertIn('1st: @@bar~//quux:bleb', stderr)
self.assertIn('2nd: @@bar~//bleb:bleb', stderr)
self.assertIn('3rd: @@//bleb:bleb', stderr)
self.assertIn('4th: @@bar~override//bleb:bleb', stderr)
self.assertIn('4th: @@bar~//bleb:bleb', stderr)
self.assertIn('5th: @@bleb//bleb:bleb', stderr)
self.assertIn('6th: @@//bleb:bleb', stderr)

Expand Down Expand Up @@ -459,10 +459,10 @@ def testWorkspaceEvaluatedBzlCanSeeRootModuleMappings(self):
stderr = '\n'.join(stderr)
# @bar is mapped to @@baz, which Bzlmod doesn't recognize, so we leave it be
self.assertIn('1st: @@baz//:z', stderr)
# @my_aaa is mapped to @@aaa, which Bzlmod remaps to @@aaa~1.0
self.assertIn('2nd: @@aaa~1.0//:z', stderr)
# @bbb isn't mapped in WORKSPACE, but Bzlmod maps it to @@bbb~1.0
self.assertIn('3rd: @@bbb~1.0//:z', stderr)
# @my_aaa is mapped to @@aaa, which Bzlmod remaps to @@aaa~
self.assertIn('2nd: @@aaa~//:z', stderr)
# @bbb isn't mapped in WORKSPACE, but Bzlmod maps it to @@bbb~
self.assertIn('3rd: @@bbb~//:z', stderr)
# @blarg isn't mapped by WORKSPACE or Bzlmod
self.assertIn('4th: @@blarg//:z', stderr)

Expand Down Expand Up @@ -641,9 +641,9 @@ def testNativeModuleNameAndVersion(self):
)
stderr = '\n'.join(stderr)
self.assertIn('@@ reporting in: [email protected]', stderr)
self.assertIn('@@foo~1.0 reporting in: [email protected]', stderr)
self.assertIn('@@foo~ reporting in: [email protected]', stderr)
self.assertIn(
'@@foo~1.0~report_ext~report_repo reporting in: [email protected]', stderr
'@@foo~~report_ext~report_repo reporting in: [email protected]', stderr
)
self.assertIn('@@bar~override reporting in: [email protected]', stderr)
self.assertIn('@@quux reporting in: None@None', stderr)
Expand Down Expand Up @@ -791,7 +791,7 @@ def testLocationNonRegistry(self):
)
self.ScratchFile('hello/MODULE.bazel', ['wat'])
_, _, stderr = self.RunBazel(['build', '@what'], allow_failure=True)
self.assertIn('ERROR: @@hello~override//:MODULE.bazel', '\n'.join(stderr))
self.assertIn('ERROR: @@hello~//:MODULE.bazel', '\n'.join(stderr))

def testLoadRulesJavaSymbolThroughBazelTools(self):
"""Tests that loads from @bazel_tools that delegate to other modules resolve."""
Expand Down
6 changes: 3 additions & 3 deletions src/test/py/bazel/bzlmod/bazel_overrides_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def testCmdAbsoluteModuleOverride(self):
)
# module file override should be ignored, and bb directory should be used
self.assertIn(
'Target @@ss~override//:choose_me up-to-date (nothing to build)', stderr
'Target @@ss~//:choose_me up-to-date (nothing to build)', stderr
)

def testCmdRelativeModuleOverride(self):
Expand Down Expand Up @@ -303,7 +303,7 @@ def testCmdRelativeModuleOverride(self):
cwd=self.Path('aa/cc'),
)
self.assertIn(
'Target @@ss~override//:choose_me up-to-date (nothing to build)', stderr
'Target @@ss~//:choose_me up-to-date (nothing to build)', stderr
)

def testCmdWorkspaceRelativeModuleOverride(self):
Expand Down Expand Up @@ -338,7 +338,7 @@ def testCmdWorkspaceRelativeModuleOverride(self):
cwd=self.Path('aa'),
)
self.assertIn(
'Target @@ss~override//:choose_me up-to-date (nothing to build)', stderr
'Target @@ss~//:choose_me up-to-date (nothing to build)', stderr
)


Expand Down
10 changes: 5 additions & 5 deletions src/test/py/bazel/bzlmod/bazel_repo_mapping_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ def testRunfilesRepoMappingManifest(self):
with open(self.Path(path), 'r') as f:
self.assertEqual(
f.read().strip(),
""",foo,foo~1.0
""",foo,foo~
,me,_main
,me_ws,_main
foo~1.0,foo,foo~1.0
foo~1.0,quux,quux~2.0
foo~,foo,foo~
foo~,quux,quux~2.0
quux~2.0,quux,quux~2.0""",
)
with open(self.Path('bazel-bin/me.runfiles_manifest')) as f:
Expand All @@ -184,8 +184,8 @@ def testRunfilesRepoMappingManifest(self):
with open(self.Path(path), 'r') as f:
self.assertEqual(
f.read().strip(),
"""bar~2.0,bar,bar~2.0
bar~2.0,quux,quux~2.0
"""bar~,bar,bar~
bar~,quux,quux~2.0
quux~2.0,quux,quux~2.0""",
)
with open(
Expand Down
24 changes: 12 additions & 12 deletions src/test/py/bazel/bzlmod/bazel_vendor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def testBasicVendoring(self):

# Assert repos are vendored with marker files and .vendorignore is created
repos_vendored = os.listdir(self._test_cwd + '/vendor')
self.assertIn('aaa~1.0', repos_vendored)
self.assertIn('bbb~1.0', repos_vendored)
self.assertIn('@aaa~1.0.marker', repos_vendored)
self.assertIn('@bbb~1.0.marker', repos_vendored)
self.assertIn('aaa~', repos_vendored)
self.assertIn('bbb~', repos_vendored)
self.assertIn('@aaa~.marker', repos_vendored)
self.assertIn('@bbb~.marker', repos_vendored)
self.assertIn('.vendorignore', repos_vendored)

def testVendorFailsWithNofetch(self):
Expand Down Expand Up @@ -126,7 +126,7 @@ def testVendoringMultipleTimes(self):
self.RunBazel(['vendor', '--vendor_dir=vendor'])

_, stdout, _ = self.RunBazel(['info', 'output_base'])
repo_path = stdout[0] + '/external/aaa~1.0'
repo_path = stdout[0] + '/external/aaa~'
if self.IsWindows():
self.assertTrue(self.IsJunction(repo_path))
else:
Expand Down Expand Up @@ -175,7 +175,7 @@ def testBuildingWithVendoredRepos(self):
)
self.ScratchFile('BUILD')
self.RunBazel(['vendor', '--vendor_dir=vendor'])
self.assertIn('aaa~1.0', os.listdir(self._test_cwd + '/vendor'))
self.assertIn('aaa~', os.listdir(self._test_cwd + '/vendor'))

# Empty external & build with vendor
self.RunBazel(['clean', '--expunge'])
Expand All @@ -188,7 +188,7 @@ def testBuildingWithVendoredRepos(self):
# Assert repo aaa in {OUTPUT_BASE}/external is a symlink (junction on
# windows, this validates it was created from vendor and not fetched)=
_, stdout, _ = self.RunBazel(['info', 'output_base'])
repo_path = stdout[0] + '/external/aaa~1.0'
repo_path = stdout[0] + '/external/aaa~'
if self.IsWindows():
self.assertTrue(self.IsJunction(repo_path))
else:
Expand Down Expand Up @@ -237,19 +237,19 @@ def testIgnoreFromVendoring(self):

os.makedirs(self._test_cwd + '/vendor', exist_ok=True)
with open(self._test_cwd + '/vendor/.vendorignore', 'w') as f:
f.write('aaa~1.0\n')
f.write('aaa~\n')

self.RunBazel(['vendor', '--vendor_dir=vendor'])
repos_vendored = os.listdir(self._test_cwd + '/vendor')

# Assert bbb and the regularRepo are vendored with marker files
self.assertIn('bbb~1.0', repos_vendored)
self.assertIn('@bbb~1.0.marker', repos_vendored)
self.assertIn('bbb~', repos_vendored)
self.assertIn('@bbb~.marker', repos_vendored)
self.assertIn('_main~ext~regularRepo', repos_vendored)
self.assertIn('@_main~ext~regularRepo.marker', repos_vendored)

# Assert aaa (from .vendorignore), local and config repos are not vendored
self.assertNotIn('aaa~1.0', repos_vendored)
self.assertNotIn('aaa~', repos_vendored)
self.assertNotIn('bazel_tools', repos_vendored)
self.assertNotIn('local_config_platform', repos_vendored)
self.assertNotIn('_main~ext~localRepo', repos_vendored)
Expand Down Expand Up @@ -322,7 +322,7 @@ def testBuildingOutOfDateVendoredRepo(self):
stderr,
)
_, stdout, _ = self.RunBazel(['info', 'output_base'])
self.assertFalse(os.path.islink(stdout[0] + '/external/bbb~1.0'))
self.assertFalse(os.path.islink(stdout[0] + '/external/bbb~'))

# Assert vendoring again solves the problem
self.RunBazel(['vendor', '--vendor_dir=vendor'])
Expand Down
14 changes: 7 additions & 7 deletions src/test/py/bazel/bzlmod/bzlmod_query_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def testQueryModuleRepoTransitiveDeps(self):
'--notool_deps',
])
self.assertListEqual(
['//:main', '@my_repo//:lib_aaa', '@@ccc~1.2//:lib_ccc'], stdout)
['//:main', '@my_repo//:lib_aaa', '@@ccc~//:lib_ccc'], stdout)

def testQueryModuleRepoTransitiveDeps_consistentLabels(self):
self.ScratchFile(
Expand All @@ -103,7 +103,7 @@ def testQueryModuleRepoTransitiveDeps_consistentLabels(self):
'--consistent_labels',
])
self.assertListEqual(
['@@//:main', '@@aaa~1.0//:lib_aaa', '@@ccc~1.2//:lib_ccc'], stdout
['@@//:main', '@@aaa~1.0//:lib_aaa', '@@ccc~//:lib_ccc'], stdout
)

def testQueryModuleRepoTransitiveDeps_consistentLabels_outputPackage(self):
Expand Down Expand Up @@ -131,7 +131,7 @@ def testQueryModuleRepoTransitiveDeps_consistentLabels_outputPackage(self):
'--consistent_labels',
'--output=package',
])
self.assertListEqual(['@@//pkg', '@@aaa~1.0//', '@@ccc~1.2//'], stdout)
self.assertListEqual(['@@//pkg', '@@aaa~1.0//', '@@ccc~//'], stdout)

def testQueryModuleRepoTransitiveDeps_consistentLabels_outputBuild(self):
self.ScratchFile(
Expand Down Expand Up @@ -191,7 +191,7 @@ def testAqueryModuleRepoTransitiveDeps(self):
])
self.assertIn('Target: //:main', stdout)
self.assertIn('Target: @my_repo//:lib_aaa', stdout)
self.assertIn('Target: @@ccc~1.2//:lib_ccc', stdout)
self.assertIn('Target: @@ccc~//:lib_ccc', stdout)

def testAqueryModuleRepoTransitiveDeps_consistentLabels(self):
self.ScratchFile(
Expand Down Expand Up @@ -219,7 +219,7 @@ def testAqueryModuleRepoTransitiveDeps_consistentLabels(self):
])
self.assertIn('Target: @@//:main', stdout)
self.assertIn('Target: @@aaa~1.0//:lib_aaa', stdout)
self.assertIn('Target: @@ccc~1.2//:lib_ccc', stdout)
self.assertIn('Target: @@ccc~//:lib_ccc', stdout)

def testCqueryModuleRepoTargetsBelow(self):
self.ScratchFile('MODULE.bazel', [
Expand Down Expand Up @@ -248,7 +248,7 @@ def testCqueryModuleRepoTransitiveDeps(self):
])
self.assertRegex(stdout[0], r'^//:main \([\w\d]+\)$')
self.assertRegex(stdout[1], r'^@my_repo//:lib_aaa \([\w\d]+\)$')
self.assertRegex(stdout[2], r'^@@ccc~1.2//:lib_ccc \([\w\d]+\)$')
self.assertRegex(stdout[2], r'^@@ccc~//:lib_ccc \([\w\d]+\)$')
self.assertEqual(len(stdout), 3)

def testCqueryModuleRepoTransitiveDeps_consistentLabels(self):
Expand Down Expand Up @@ -277,7 +277,7 @@ def testCqueryModuleRepoTransitiveDeps_consistentLabels(self):
])
self.assertRegex(stdout[0], r'^@@//:main \([\w\d]+\)$')
self.assertRegex(stdout[1], r'^@@aaa~1.0//:lib_aaa \([\w\d]+\)$')
self.assertRegex(stdout[2], r'^@@ccc~1.2//:lib_ccc \([\w\d]+\)$')
self.assertRegex(stdout[2], r'^@@ccc~//:lib_ccc \([\w\d]+\)$')
self.assertEqual(len(stdout), 3)

def testFetchModuleRepoTargetsBelow(self):
Expand Down
8 changes: 4 additions & 4 deletions src/test/py/bazel/bzlmod/external_repo_completion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ def testCompletions(self):

# Packages are completed in external repos with canonical repo names.
self.assertCountEqual(
['@@ext~1.0//tools/', '@@ext~1.0//tools:'],
self.complete('build @@ext~1.0//tool'),
['@@ext~//tools/', '@@ext~//tools:'],
self.complete('build @@ext~//tool'),
)
self.assertCountEqual(
['@@ext~1.0//tools/zip/', '@@ext~1.0//tools/zip:'],
self.complete('build @@ext~1.0//tools/zi'),
['@@ext~//tools/zip/', '@@ext~//tools/zip:'],
self.complete('build @@ext~//tools/zi'),
)
self.assertCountEqual(
['@@//pkg/', '@@//pkg:'], self.complete('build @@//p')
Expand Down
Loading

0 comments on commit c077db3

Please sign in to comment.