Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1141cc4

Browse filesBrowse files
committed
tests(gazelle): Add more tests
1 parent 6433080 commit 1141cc4
Copy full SHA for 1141cc4

File tree

Expand file treeCollapse file tree

21 files changed

+89
-3
lines changed
Filter options
Expand file treeCollapse file tree

21 files changed

+89
-3
lines changed

‎gazelle/python/generate.go

Copy file name to clipboardExpand all lines: gazelle/python/generate.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func (py *Python) GenerateRules(args language.GenerateArgs) language.GenerateRes
404404
addSrc(entrypointTarget).
405405
addResolvedDependency(entrypointTarget).
406406
setMain(main)
407-
} else {
407+
} else if hasPyTestEntryPointFile {
408408
pyTestTarget.setMain(pyTestEntrypointFilename)
409409
}
410410
pyTestTargets = append(pyTestTargets, pyTestTarget)

‎gazelle/python/testdata/monorepo/coarse_grained/BUILD.out

Copy file name to clipboardExpand all lines: gazelle/python/testdata/monorepo/coarse_grained/BUILD.out
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ py_test(
2525
"bar/bar_test.py",
2626
"foo/bar/bar_test.py",
2727
],
28-
main = "__test__.py",
2928
)

‎gazelle/python/testdata/project_generation_mode/BUILD.out

Copy file name to clipboardExpand all lines: gazelle/python/testdata/project_generation_mode/BUILD.out
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ load("@rules_python//python:defs.bzl", "py_library")
55

66
py_library(
77
name = "project_generation_mode",
8-
srcs = ["__init__.py"],
8+
srcs = [
9+
"__init__.py",
10+
"bar/bar.py",
11+
"foo/foo.py",
12+
],
913
visibility = ["//:__subpackages__"],
1014
)
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Project generation mode
2+
3+
Simple example using `gazelle:python_generation_mode project` in a project with no tests.

‎gazelle/python/testdata/project_generation_mode/bar/bar.py

Copy file name to clipboardExpand all lines: gazelle/python/testdata/project_generation_mode/bar/bar.py
Whitespace-only changes.

‎gazelle/python/testdata/project_generation_mode/foo/foo.py

Copy file name to clipboardExpand all lines: gazelle/python/testdata/project_generation_mode/foo/foo.py
Whitespace-only changes.
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# gazelle:python_extension enabled
2+
# gazelle:python_generation_mode project
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
load("@rules_python//python:defs.bzl", "py_library", "py_test")
2+
3+
# gazelle:python_extension enabled
4+
# gazelle:python_generation_mode project
5+
6+
py_library(
7+
name = "project_generation_mode_with_test_entrypoint",
8+
srcs = ["__init__.py"],
9+
visibility = ["//:__subpackages__"],
10+
)
11+
12+
py_test(
13+
name = "project_generation_mode_with_test_entrypoint_test",
14+
srcs = [
15+
"__test__.py",
16+
"foo/foo_test.py",
17+
],
18+
main = "__test__.py",
19+
)
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Project generation mode with test entrypoint
2+
3+
Example using `gazelle:python_generation_mode project` in a project with tests that use an explicit `__test__.py` entrypoint.
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This is a Bazel workspace for the Gazelle test data.

‎gazelle/python/testdata/project_generation_mode_with_test_entrypoint/__init__.py

Copy file name to clipboardExpand all lines: gazelle/python/testdata/project_generation_mode_with_test_entrypoint/__init__.py
Whitespace-only changes.

‎gazelle/python/testdata/project_generation_mode_with_test_entrypoint/__test__.py

Copy file name to clipboardExpand all lines: gazelle/python/testdata/project_generation_mode_with_test_entrypoint/__test__.py
Whitespace-only changes.

‎gazelle/python/testdata/project_generation_mode_with_test_entrypoint/foo/foo_test.py

Copy file name to clipboardExpand all lines: gazelle/python/testdata/project_generation_mode_with_test_entrypoint/foo/foo_test.py
Whitespace-only changes.
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# gazelle:python_extension enabled
2+
# gazelle:python_generation_mode project
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load("@rules_python//python:defs.bzl", "py_library", "py_test")
2+
3+
# gazelle:python_extension enabled
4+
# gazelle:python_generation_mode project
5+
6+
py_library(
7+
name = "project_generation_mode_with_tests",
8+
srcs = ["__init__.py"],
9+
visibility = ["//:__subpackages__"],
10+
)
11+
12+
py_test(
13+
name = "project_generation_mode_with_tests_test",
14+
srcs = ["foo/foo_test.py"],
15+
)
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Project generation mode with tests
2+
3+
Example using `gazelle:python_generation_mode project` in a project with tests, but no `__test__.py` entrypoint.
4+
5+
Note that, in this mode, the `py_test` rule will have no `main` set, which will fail to run with the standard
6+
`py_test` rule. However, this can be used in conjunction with `gazelle:map_kind` to use some other implementation
7+
of `py_test` that is able to handle this sitation (such as `rules_python_pytest`).
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# This is a Bazel workspace for the Gazelle test data.

‎gazelle/python/testdata/project_generation_mode_with_tests/__init__.py

Copy file name to clipboardExpand all lines: gazelle/python/testdata/project_generation_mode_with_tests/__init__.py
Whitespace-only changes.

‎gazelle/python/testdata/project_generation_mode_with_tests/foo/foo_test.py

Copy file name to clipboardExpand all lines: gazelle/python/testdata/project_generation_mode_with_tests/foo/foo_test.py
Whitespace-only changes.
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
---

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.