From 16bd4306a815c468b4071b6df0537599f0b8c3e4 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Wed, 23 Sep 2009 18:22:02 -0700 Subject: [PATCH] models.main: Fix the tests for {stage,unstage,revert}_paths() The old code would silently call update_status() so that its view of the world was up-to-date before issuing git commands. The tests check for this behavior, so reinstate the original behavior from the classic model. Signed-off-by: David Aguilar --- cola/models/main.py | 3 +++ test/test_cola_models_classic.py | 30 +++++++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/cola/models/main.py b/cola/models/main.py index 2117d085..aa12a4c2 100644 --- a/cola/models/main.py +++ b/cola/models/main.py @@ -1221,6 +1221,7 @@ class MainModel(ObservableModel): """Adds paths to git and notifies observers.""" # Grab the old lists of untracked + modified files + self.update_status() old_modified = set(self.modified) old_untracked = set(self.untracked) @@ -1253,6 +1254,7 @@ class MainModel(ObservableModel): paths = set(paths) # Grab the old list of staged files + self.update_status() old_staged = set(self.staged) # Reset and scan for new changes @@ -1274,6 +1276,7 @@ class MainModel(ObservableModel): paths = set(paths) # Grab the old set of changed files + self.update_status() old_modified = set(self.modified) old_staged = set(self.staged) old_changed = old_modified.union(old_staged) diff --git a/test/test_cola_models_classic.py b/test/test_cola_models_classic.py index f65e450b..f6d48e10 100644 --- a/test/test_cola_models_classic.py +++ b/test/test_cola_models_classic.py @@ -1,7 +1,7 @@ """Covers interfaces used by the classic view.""" +import os import helper - from cola.models.main import MainModel class MainModelObserver(object): @@ -37,17 +37,20 @@ class ClassicModelTestCase(helper.TestCase): """Test the MainModel.everything() method.""" self.setup_baseline_repo() self.shell('touch other-file') - model = MainModel() + + model = MainModel(cwd=os.getcwd()) + model.update_status() + everything = model.everything() self.assertTrue('the-file' in everything) self.assertTrue('other-file' in everything) def test_stage_paths(self): - """Test a simple usage of MainModel.stage_paths.""" + """Test a simple usage of stage_paths().""" self.setup_baseline_repo() self.shell('echo change > the-file') - model = MainModel() + model = MainModel(cwd=os.getcwd()) observer = MainModelObserver(model) model.stage_paths(['the-file']) @@ -63,8 +66,9 @@ class ClassicModelTestCase(helper.TestCase): echo change > foo/bar/baz """) - model = MainModel() + model = MainModel(cwd=os.getcwd()) observer = MainModelObserver(model) + model.stage_paths(['foo']) self.assertTrue('foo' in observer.paths) @@ -87,8 +91,9 @@ class ClassicModelTestCase(helper.TestCase): touch foo/bar/baz """) - model = MainModel() + model = MainModel(cwd=os.getcwd()) observer = MainModelObserver(model) + model.stage_paths(['foo']) self.assertTrue('foo' in observer.paths) @@ -106,7 +111,7 @@ class ClassicModelTestCase(helper.TestCase): git add the-file """) - model = MainModel() + model = MainModel(cwd=os.getcwd()) observer = MainModelObserver(model) model.unstage_paths(['the-file']) @@ -117,8 +122,10 @@ class ClassicModelTestCase(helper.TestCase): def test_unstage_paths_init(self): """Test unstage_paths() on the root commit.""" self.setup_baseline_repo(commit=False) - model = MainModel() + + model = MainModel(cwd=os.getcwd()) observer = MainModelObserver(model) + model.unstage_paths(['the-file']) self.assertTrue('the-file' in observer.paths) @@ -134,8 +141,9 @@ class ClassicModelTestCase(helper.TestCase): git add foo/bar/baz """) - model = MainModel() + model = MainModel(os.getcwd()) observer = MainModelObserver(model) + model.unstage_paths(['foo']) self.assertTrue('foo' in observer.paths) @@ -149,7 +157,7 @@ class ClassicModelTestCase(helper.TestCase): self.setup_baseline_repo() self.shell('echo change > the-file') - model = MainModel() + model = MainModel(cwd=os.getcwd()) observer = MainModelObserver(model) model.revert_paths(['the-file']) @@ -167,7 +175,7 @@ class ClassicModelTestCase(helper.TestCase): echo change > foo/bar/baz """) - model = MainModel() + model = MainModel(cwd=os.getcwd()) observer = MainModelObserver(model) model.revert_paths(['foo']) -- 2.11.4.GIT