|
| 1 | +# Copyright © 2011-2026 Splunk, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"): you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# 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, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | + |
| 15 | +import os |
| 16 | + |
| 17 | +import pytest |
| 18 | + |
| 19 | +from splunklib.searchcommands.environment import ( |
| 20 | + _find_app_root, # pyright: ignore[reportPrivateUsage] |
| 21 | +) |
| 22 | + |
| 23 | + |
| 24 | +@pytest.mark.parametrize( |
| 25 | + ("app_file_parts", "expected_app_root_parts"), |
| 26 | + [ |
| 27 | + (("apps", "my_app", "bin", "command.py"), ("apps", "my_app")), |
| 28 | + (("apps", "my_app", "bin", "linux_x86_64", "command.py"), ("apps", "my_app")), |
| 29 | + (("apps", "my_app", "bin", "foo", "bar", "command.py"), ("apps", "my_app")), |
| 30 | + (("some", "other", "layout", "command.py"), ("some", "other")), |
| 31 | + ], |
| 32 | +) |
| 33 | +def test_find_app_root( |
| 34 | + app_file_parts: tuple[str, ...], expected_app_root_parts: tuple[str, ...] |
| 35 | +) -> None: |
| 36 | + app_file = os.path.join(*app_file_parts) |
| 37 | + assert _find_app_root(app_file) == os.path.abspath(os.path.join(*expected_app_root_parts)) |
0 commit comments