travis: run tests using tox
[git-cola.git] / test / cmds_test.py
blob122f712981274a1a0a957d15e1ce0cf0a3e96025
1 #!/usr/bin/env python
2 from __future__ import absolute_import, division, unicode_literals
3 import unittest
4 try:
5 from unittest import mock
6 except ImportError:
7 import mock
9 from cola import cmds
10 from cola.compat import uchr
13 class CmdsTestCase(unittest.TestCase):
14 """Tests the cola.core module's unicode handling
15 """
17 def test_Commit_strip_comments(self):
18 """Ensure that commit messages are stripped of comments"""
20 msg = 'subject\n\n#comment\nbody'
21 expect = 'subject\n\nbody\n'
22 actual = cmds.Commit.strip_comments(msg)
23 self.assertEqual(expect, actual)
25 def test_Commit_strip_comments_unicode(self):
26 """Ensure that unicode is preserved in stripped commit messages"""
28 msg = uchr(0x1234) + '\n\n#comment\nbody'
29 expect = uchr(0x1234) + '\n\nbody\n'
30 actual = cmds.Commit.strip_comments(msg)
31 self.assertEqual(expect, actual)
33 def test_unix_path_win32(self):
34 path = r'Z:\Program Files\git-cola\bin\git-dag'
35 expect = '/Z/Program Files/git-cola/bin/git-dag'
36 actual = cmds.unix_path(path, is_win32=lambda: True)
37 self.assertEqual(expect, actual)
39 def test_unix_path_network_win32(self):
40 path = r'\\Z\Program Files\git-cola\bin\git-dag'
41 expect = '//Z/Program Files/git-cola/bin/git-dag'
42 actual = cmds.unix_path(path, is_win32=lambda: True)
43 self.assertEqual(expect, actual)
45 def test_unix_path_is_a_noop_on_sane_platforms(self):
46 path = r'/:we/don\t/need/no/stinking/badgers!'
47 expect = path
48 actual = cmds.unix_path(path, is_win32=lambda: False)
49 self.assertEqual(expect, actual)
51 def test_context_edit_command(self):
52 context = mock.Mock()
53 model = context.model
55 cmd = cmds.EditModel(context)
56 cmd.new_diff_text = 'test_diff_text'
57 cmd.new_diff_type = 'test_diff_type'
58 cmd.new_mode = 'test_mode'
59 cmd.new_filename = 'test_filename'
60 cmd.do()
62 model.set_diff_text.assert_called_once_with('test_diff_text')
63 model.set_diff_type.assert_called_once_with('test_diff_type')
64 model.set_mode.assert_called_once_with('test_mode')
65 model.set_filename.assert_called_once_with('test_filename')
66 self.assertEqual(model.set_filename.call_count, 1)
69 if __name__ == '__main__':
70 unittest.main()