Trent Apted | 7246835 | 2023-07-11 16:15:57 +1000 | [diff] [blame^] | 1 | # Copyright 2023 The ChromiumOS Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Tests for the analyzers module.""" |
| 6 | |
| 7 | from chromite.cli import analyzers |
| 8 | |
| 9 | |
| 10 | def test_get_files_from_commit(run_mock) -> None: |
| 11 | run_mock.AddCmdResult( |
| 12 | ["git", "rev-parse", "--show-toplevel"], stdout="/path/to/root\n" |
| 13 | ) |
| 14 | run_mock.SetDefaultCmdResult(stdout="file1\nsub/file2\n") |
| 15 | assert analyzers.GetFilesFromCommit("ignored") == [ |
| 16 | "/path/to/root/file1", |
| 17 | "/path/to/root/sub/file2", |
| 18 | ] |
| 19 | |
| 20 | |
| 21 | def test_has_uncommitted_changes(run_mock) -> None: |
| 22 | run_mock.SetDefaultCmdResult(stdout="M file\n") |
| 23 | assert analyzers.HasUncommittedChanges(["/path/to/file"]) is True |
| 24 | |
| 25 | |
| 26 | def test_has_no_uncommitted_changes(run_mock) -> None: |
| 27 | run_mock.SetDefaultCmdResult(stdout="") |
| 28 | assert analyzers.HasUncommittedChanges(["/path/to/file"]) is False |