1 """Covers interfaces used by the classic view."""
5 from cola
.models
.main
import MainModel
8 class ClassicModelTestCase(helper
.TestCase
):
9 """Tests interfaces used by the classic view."""
11 def setup_baseline_repo(self
, commit
=True):
12 """Create a baseline repo for testing."""
14 git init >/dev/null &&
19 self
.shell("git commit -s -m'Initial commit' >/dev/null")
21 def test_everything(self
):
22 """Test the MainModel.everything() method."""
23 self
.setup_baseline_repo()
24 self
.shell('touch other-file')
26 model
= MainModel(cwd
=os
.getcwd())
29 everything
= model
.everything()
30 self
.assertTrue('the-file' in everything
)
31 self
.assertTrue('other-file' in everything
)
33 def test_stage_paths_untracked(self
):
34 """Test stage_paths() with an untracked file."""
35 self
.setup_baseline_repo()
40 model
= MainModel(cwd
=os
.getcwd())
41 model
.stage_paths(['foo'])
43 self
.assertTrue('foo/bar/baz' in model
.staged
)
44 self
.assertTrue('foo/bar/baz' not in model
.modified
)
45 self
.assertTrue('foo/bar/baz' not in model
.untracked
)
47 def test_unstage_paths(self
):
48 """Test a simple usage of unstage_paths()."""
49 self
.setup_baseline_repo()
51 echo change > the-file &&
55 model
= MainModel(cwd
=os
.getcwd())
56 model
.unstage_paths(['the-file'])
58 self
.assertTrue('the-file' not in model
.staged
)
59 self
.assertTrue('the-file' in model
.modified
)
61 def test_unstage_paths_init(self
):
62 """Test unstage_paths() on the root commit."""
63 self
.setup_baseline_repo(commit
=False)
65 model
= MainModel(cwd
=os
.getcwd())
66 model
.unstage_paths(['the-file'])
68 self
.assertTrue('the-file' not in model
.staged
)
69 self
.assertTrue('the-file' in model
.untracked
)
71 def test_unstage_paths_subdir(self
):
72 """Test unstage_paths() in a subdirectory."""
73 self
.setup_baseline_repo()
79 model
= MainModel(os
.getcwd())
80 model
.unstage_paths(['foo'])
82 self
.assertTrue('foo/bar/baz' in model
.untracked
)
83 self
.assertTrue('foo/bar/baz' not in model
.staged
)
85 def test_revert_paths(self
):
86 """Test a simple use of 'revert_paths'."""
87 self
.setup_baseline_repo()
88 self
.shell('echo change > the-file')
90 model
= MainModel(cwd
=os
.getcwd())
91 model
.revert_paths(['the-file'])
93 self
.assertTrue('the-file' not in model
.staged
)
94 self
.assertTrue('the-file' not in model
.modified
)
96 def test_revert_paths_subdir(self
):
97 self
.setup_baseline_repo()
101 git add foo/bar/baz &&
102 git commit -m'Changed foo/bar/baz' >/dev/null &&
103 echo change > foo/bar/baz
106 model
= MainModel(cwd
=os
.getcwd())
107 model
.revert_paths(['foo'])
109 self
.assertTrue('foo/bar/baz' not in model
.modified
)
110 self
.assertTrue('foo/bar/baz' not in model
.staged
)