blob: ffed3748b5173608030e0de18cf5a3f9ee896d11 [file] [log] [blame]
Trent Apted72468352023-07-11 16:15:57 +10001# 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
7from chromite.cli import analyzers
8
9
10def 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
21def 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
26def test_has_no_uncommitted_changes(run_mock) -> None:
27 run_mock.SetDefaultCmdResult(stdout="")
28 assert analyzers.HasUncommittedChanges(["/path/to/file"]) is False