contrib: remove all references to Python 2.6 and travis-build
[git-cola.git] / test / browse_model_test.py
blobf009a8a733ef61e853e30e97d9bac2d4d0e3f3ad
1 """Test interfaces used by the browser (git cola browse)"""
2 # pylint: disable=redefined-outer-name
3 from __future__ import absolute_import, division, unicode_literals
5 from cola import core
6 from cola import gitcmds
8 from . import helper
9 # NOTE: run_in_tmpdir is required by pytest even though it is only used indirectly.
10 from .helper import run_in_tmpdir
11 from .helper import app_context
14 # These assertions make flake8 happy. It considers them unused imports otherwise.
15 assert run_in_tmpdir is not None
16 assert app_context is not None
19 def test_stage_paths_untracked(app_context):
20 """Test stage_paths() with an untracked file."""
21 model = app_context.model
22 core.makedirs('foo/bar')
23 helper.touch('foo/bar/baz')
24 gitcmds.add(app_context, ['foo'])
25 app_context.model.update_file_status()
27 assert 'foo/bar/baz' in model.staged
28 assert 'foo/bar/baz' not in model.modified
29 assert 'foo/bar/baz' not in model.untracked
32 def test_unstage_paths(app_context):
33 """Test a simple usage of unstage_paths()."""
34 helper.commit_files()
35 helper.write_file('A', 'change')
36 helper.run_git('add', 'A')
37 model = app_context.model
39 gitcmds.unstage_paths(app_context, ['A'])
40 model.update_status()
42 assert 'A' not in model.staged
43 assert 'A' in model.modified
46 def test_unstage_paths_init(app_context):
47 """Test unstage_paths() on the root commit."""
48 model = app_context.model
49 gitcmds.unstage_paths(app_context, ['A'])
50 model.update_status()
52 assert 'A' not in model.staged
53 assert 'A' in model.untracked
56 def test_unstage_paths_subdir(app_context):
57 """Test unstage_paths() in a subdirectory."""
58 helper.run_git('commit', '-m', 'initial commit')
59 core.makedirs('foo/bar')
60 helper.touch('foo/bar/baz')
61 helper.run_git('add', 'foo/bar/baz')
62 model = app_context.model
64 gitcmds.unstage_paths(app_context, ['foo'])
65 model.update_status()
67 assert 'foo/bar/baz' in model.untracked
68 assert 'foo/bar/baz' not in model.staged