Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/tests/test_pre_commit_copyright.py
4255 views
1
import pytest
2
from unittest.mock import patch
3
4
from Tools.gittools.pre_commit_copyright import get_file_paths
5
6
7
def test_get_file_paths_no_args():
8
"""Test get_file_paths with no command line arguments."""
9
with patch('sys.argv', ["pre_commit_copyright.py"]):
10
with pytest.raises(SystemExit, match="2"):
11
_ = get_file_paths()
12
13
14
@pytest.mark.parametrize(
15
"argv, expected",
16
[
17
(
18
["pre_commit_copyright.py", "file1.py", "file2.py", "file3.py"],
19
["file1.py", "file2.py", "file3.py"]
20
),
21
(
22
["pre_commit_copyright.py", "file1.py", "file2.py", "--ignore=file2.py"],
23
["file1.py"]
24
),
25
(
26
["pre_commit_copyright.py", "file1.py", "file2.py", "file3.py", "--ignore=file1.py", "--ignore=file3.py"],
27
["file2.py"]
28
),
29
(
30
["pre_commit_copyright.py", "file1.py", "file2.py", "--ignore=excluded_file.py", "--ignore=another_excluded.py"],
31
["file1.py", "file2.py"]
32
),
33
(
34
["pre_commit_copyright.py", "file1.py", "--ignore=file1.py"],
35
[]
36
),
37
]
38
)
39
def test_get_file_paths_parametrized(argv, expected):
40
"""Test get_file_paths with various command line argument combinations."""
41
with patch('sys.argv', argv):
42
assert get_file_paths() == expected
43
44