Skip to content

Commit

Permalink
fix: gazelle correctly adds new py_test rules
Browse files Browse the repository at this point in the history
  • Loading branch information
amartani committed Apr 1, 2023
1 parent 260a08b commit 94c50f4
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gazelle/python/kinds.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var pyKinds = map[string]rule.KindInfo{
},
},
pyTestKind: {
MatchAny: true,
MatchAny: false,
NonEmptyAttrs: map[string]bool{
"deps": true,
"main": true,
Expand Down
12 changes: 12 additions & 0 deletions gazelle/python/testdata/multiple_tests/BUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@rules_python//python:defs.bzl", "py_library", "py_test")

py_library(
name = "multiple_tests",
srcs = ["__init__.py"],
visibility = ["//:__subpackages__"],
)

py_test(
name = "bar_test",
srcs = ["bar_test.py"],
)
17 changes: 17 additions & 0 deletions gazelle/python/testdata/multiple_tests/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
load("@rules_python//python:defs.bzl", "py_library", "py_test")

py_library(
name = "multiple_tests",
srcs = ["__init__.py"],
visibility = ["//:__subpackages__"],
)

py_test(
name = "bar_test",
srcs = ["bar_test.py"],
)

py_test(
name = "foo_test",
srcs = ["foo_test.py"],
)
3 changes: 3 additions & 0 deletions gazelle/python/testdata/multiple_tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Multiple tests

This test case asserts that a second `py_test` rule is correctly created when a second `*_test.py` file is added to a package with an existing `py_test` rule.
1 change: 1 addition & 0 deletions gazelle/python/testdata/multiple_tests/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is a Bazel workspace for the Gazelle test data.
Empty file.
24 changes: 24 additions & 0 deletions gazelle/python/testdata/multiple_tests/bar_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest


class BarTest(unittest.TestCase):
def test_foo(self):
pass


if __name__ == "__main__":
unittest.main()
24 changes: 24 additions & 0 deletions gazelle/python/testdata/multiple_tests/foo_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest


class FooTest(unittest.TestCase):
def test_foo(self):
pass


if __name__ == "__main__":
unittest.main()
17 changes: 17 additions & 0 deletions gazelle/python/testdata/multiple_tests/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

---
expect:
exit_code: 0

0 comments on commit 94c50f4

Please sign in to comment.