sysmon: Add metrics for unstaged git changes
Not sure if this is papering over a bug, but this is currently
breaking by workflow
BUG=chromium:724580
TEST=None
Change-Id: If2011dbadca93ecd7f270aed120ee359113707d9
Reviewed-on: https://chromium-review.googlesource.com/544104
Commit-Ready: Allen Li <ayatane@chromium.org>
Tested-by: Allen Li <ayatane@chromium.org>
Reviewed-by: Paul Hobbs <phobbs@google.com>
diff --git a/scripts/sysmon/git_metrics_unittest.py b/scripts/sysmon/git_metrics_unittest.py
index 470124e..8eaefc8 100644
--- a/scripts/sysmon/git_metrics_unittest.py
+++ b/scripts/sysmon/git_metrics_unittest.py
@@ -66,6 +66,30 @@
])
+class TestGitRepoWithTempdir(cros_test_lib.TempDirTestCase):
+ """Tests for _GitRepo using a Git fixture."""
+
+ def setUp(self):
+ self.git_dir = os.path.join(self.tempdir, '.git')
+ with osutils.ChdirContext(self.tempdir):
+ self.git_repo = git_metrics._GitRepo(self.git_dir)
+ self.git_repo._check_output(['init'])
+ with open('foo', 'w') as f:
+ f.write('a\nb\nc\n')
+ self.git_repo._check_output(['add', 'foo'])
+ self.git_repo._check_output(['commit', '-m', 'hi'])
+
+ def test_get_unstaged_changes(self):
+ """Test get_unstaged_changes."""
+ with open(os.path.join(self.tempdir, 'spam'), 'w') as f:
+ f.write('a\n')
+ os.remove(os.path.join(self.tempdir, 'foo'))
+ repo = git_metrics._GitRepo(self.git_dir)
+ added, removed = repo.get_unstaged_changes()
+ self.assertEqual(added, 0) # Does not count untracked files
+ self.assertEqual(removed, 3)
+
+
class TestMetricCollector(cros_test_lib.TestCase):
"""Tests for _GitMetricCollector."""