themes: use the core module for io
[git-cola.git] / test / browse_model_test.py
blobbea9584e55c5d9cb5367cdbbec868f1b0321b5e6
1 """Test interfaces used by the browser (git cola browse)"""
2 # pylint: disable=redefined-outer-name
3 from __future__ import absolute_import, division, print_function, unicode_literals
5 from cola import core
6 from cola import gitcmds
8 from . import helper
9 from .helper import app_context
12 # These assertions make flake8 happy. It considers them unused imports otherwise.
13 assert app_context is not None
16 def test_stage_paths_untracked(app_context):
17 """Test stage_paths() with an untracked file."""
18 model = app_context.model
19 core.makedirs('foo/bar')
20 helper.touch('foo/bar/baz')
21 gitcmds.add(app_context, ['foo'])
22 app_context.model.update_file_status()
24 assert 'foo/bar/baz' in model.staged
25 assert 'foo/bar/baz' not in model.modified
26 assert 'foo/bar/baz' not in model.untracked
29 def test_unstage_paths(app_context):
30 """Test a simple usage of unstage_paths()."""
31 helper.commit_files()
32 helper.write_file('A', 'change')
33 helper.run_git('add', 'A')
34 model = app_context.model
36 gitcmds.unstage_paths(app_context, ['A'])
37 model.update_status()
39 assert 'A' not in model.staged
40 assert 'A' in model.modified
43 def test_unstage_paths_init(app_context):
44 """Test unstage_paths() on the root commit."""
45 model = app_context.model
46 gitcmds.unstage_paths(app_context, ['A'])
47 model.update_status()
49 assert 'A' not in model.staged
50 assert 'A' in model.untracked
53 def test_unstage_paths_subdir(app_context):
54 """Test unstage_paths() in a subdirectory."""
55 helper.run_git('commit', '-m', 'initial commit')
56 core.makedirs('foo/bar')
57 helper.touch('foo/bar/baz')
58 helper.run_git('add', 'foo/bar/baz')
59 model = app_context.model
61 gitcmds.unstage_paths(app_context, ['foo'])
62 model.update_status()
64 assert 'foo/bar/baz' in model.untracked
65 assert 'foo/bar/baz' not in model.staged