tests: prefer functions over methods
Signed-off-by: David Aguilar <davvid@gmail.com>
This commit is contained in:
@@ -12,11 +12,13 @@ class AppTestCase(unittest.TestCase):
|
||||
|
||||
def test_setup_environment(self):
|
||||
# If the function doesn't throw an exception we are happy.
|
||||
self.assertTrue(hasattr(app, 'setup_environment'))
|
||||
app.setup_environment()
|
||||
|
||||
def test_add_common_arguments(self):
|
||||
# If the function doesn't throw an exception we are happy.
|
||||
parser = argparse.ArgumentParser()
|
||||
self.assertTrue(hasattr(app, 'add_common_arguments'))
|
||||
app.add_common_arguments(parser)
|
||||
|
||||
|
||||
|
||||
+20
-19
@@ -48,7 +48,7 @@ class BranchesTreeHelperTestCase(unittest.TestCase):
|
||||
|
||||
def test_should_return_a_valid_top_item_on_get_root(self):
|
||||
"""Test the get_root function."""
|
||||
items = self._create_top_item()
|
||||
items = _create_top_item()
|
||||
tree_helper = BranchesTreeHelper()
|
||||
|
||||
result = tree_helper.get_root(items['child_1'])
|
||||
@@ -59,7 +59,7 @@ class BranchesTreeHelperTestCase(unittest.TestCase):
|
||||
|
||||
def test_should_return_a_valid_branch_name_on_get_full_name(self):
|
||||
"""Test the get_full_name function."""
|
||||
items = self._create_top_item()
|
||||
items = _create_top_item()
|
||||
tree_helper = BranchesTreeHelper()
|
||||
|
||||
result = tree_helper.get_full_name(items['child_1'], '/')
|
||||
@@ -70,7 +70,7 @@ class BranchesTreeHelperTestCase(unittest.TestCase):
|
||||
|
||||
def test_should_return_a_valid_child_on_find_child(self):
|
||||
"""Test the find_child function."""
|
||||
items = self._create_top_item()
|
||||
items = _create_top_item()
|
||||
tree_helper = BranchesTreeHelper()
|
||||
|
||||
child = tree_helper.find_child(items['top'], 'child_1')
|
||||
@@ -81,7 +81,7 @@ class BranchesTreeHelperTestCase(unittest.TestCase):
|
||||
|
||||
def test_should_return_empty_state_on_save_state(self):
|
||||
"""Test the save_state function."""
|
||||
top = self._create_item('top', False)
|
||||
top = _create_item('top', False)
|
||||
tree_helper = BranchesTreeHelper()
|
||||
|
||||
result = tree_helper.save_state(top)
|
||||
@@ -89,31 +89,32 @@ class BranchesTreeHelperTestCase(unittest.TestCase):
|
||||
|
||||
def test_should_return_a_valid_state_on_save_state(self):
|
||||
"""Test the save_state function."""
|
||||
items = self._create_top_item()
|
||||
items = _create_top_item()
|
||||
tree_helper = BranchesTreeHelper()
|
||||
|
||||
result = tree_helper.save_state(items['top'])
|
||||
self.assertEqual({'top': {'child_1': {}, 'child_2': {
|
||||
'sub_child_2_1': {}, 'sub_child_2_2': {}}}}, result)
|
||||
|
||||
def _create_item(self, name, expanded):
|
||||
item = BranchTreeWidgetItem(name)
|
||||
item.isExpanded = MagicMock(return_value=expanded)
|
||||
|
||||
return item
|
||||
def _create_top_item():
|
||||
top = _create_item('top', True)
|
||||
child_1 = _create_item('child_1', False)
|
||||
child_2 = _create_item('child_2', True)
|
||||
sub_child_2_1 = _create_item('sub_child_2_1', False)
|
||||
sub_child_2_2 = _create_item('sub_child_2_2', False)
|
||||
|
||||
def _create_top_item(self):
|
||||
top = self._create_item('top', True)
|
||||
child_1 = self._create_item('child_1', False)
|
||||
child_2 = self._create_item('child_2', True)
|
||||
sub_child_2_1 = self._create_item('sub_child_2_1', False)
|
||||
sub_child_2_2 = self._create_item('sub_child_2_2', False)
|
||||
child_2.addChildren([sub_child_2_1, sub_child_2_2])
|
||||
top.addChildren([child_1, child_2])
|
||||
|
||||
child_2.addChildren([sub_child_2_1, sub_child_2_2])
|
||||
top.addChildren([child_1, child_2])
|
||||
return {'top': top, 'child_1': child_1, 'sub_child_2_1': sub_child_2_1,
|
||||
'sub_child_2_2': sub_child_2_2}
|
||||
|
||||
return {'top': top, 'child_1': child_1, 'sub_child_2_1': sub_child_2_1,
|
||||
'sub_child_2_2': sub_child_2_2}
|
||||
|
||||
def _create_item(name, expanded):
|
||||
item = BranchTreeWidgetItem(name)
|
||||
item.isExpanded = MagicMock(return_value=expanded)
|
||||
return item
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -63,6 +63,7 @@ class CmdsTestCase(unittest.TestCase):
|
||||
model.set_diff_type.assert_called_once_with('test_diff_type')
|
||||
model.set_mode.assert_called_once_with('test_mode')
|
||||
model.set_filename.assert_called_once_with('test_filename')
|
||||
self.assertEqual(model.set_filename.call_count, 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
+14
-13
@@ -8,29 +8,30 @@ from cola.settings import Settings
|
||||
from . import helper
|
||||
|
||||
|
||||
def new_settings(**kwargs):
|
||||
settings = Settings(**kwargs)
|
||||
settings.load()
|
||||
return settings
|
||||
|
||||
|
||||
class SettingsTestCase(unittest.TestCase):
|
||||
"""Tests the cola.settings module"""
|
||||
|
||||
def setUp(self):
|
||||
Settings.config_path = self._file = helper.tmp_path('settings')
|
||||
self.settings = self.new_settings()
|
||||
self.settings = new_settings()
|
||||
|
||||
def tearDown(self):
|
||||
if os.path.exists(self._file):
|
||||
os.remove(self._file)
|
||||
|
||||
def new_settings(self, **kwargs):
|
||||
settings = Settings(**kwargs)
|
||||
settings.load()
|
||||
return settings
|
||||
|
||||
def test_gui_save_restore(self):
|
||||
"""Test saving and restoring gui state"""
|
||||
settings = self.new_settings()
|
||||
settings = new_settings()
|
||||
settings.gui_state['test-gui'] = {'foo': 'bar'}
|
||||
settings.save()
|
||||
|
||||
settings = self.new_settings()
|
||||
settings = new_settings()
|
||||
state = settings.gui_state.get('test-gui', {})
|
||||
self.assertTrue('foo' in state)
|
||||
self.assertEqual(state['foo'], 'bar')
|
||||
@@ -47,11 +48,11 @@ class SettingsTestCase(unittest.TestCase):
|
||||
def mock_verify(path):
|
||||
return path == bookmark['path']
|
||||
|
||||
settings = self.new_settings()
|
||||
settings = new_settings()
|
||||
settings.add_bookmark(bookmark['path'], bookmark['name'])
|
||||
settings.save()
|
||||
|
||||
settings = self.new_settings(verify=mock_verify)
|
||||
settings = new_settings(verify=mock_verify)
|
||||
|
||||
bookmarks = settings.bookmarks
|
||||
self.assertEqual(len(settings.bookmarks), 1)
|
||||
@@ -65,17 +66,17 @@ class SettingsTestCase(unittest.TestCase):
|
||||
def test_bookmarks_removes_missing_entries(self):
|
||||
"""Test that missing entries are removed after a reload"""
|
||||
bookmark = {'path': '/tmp/this/does/not/exist', 'name': 'notexist'}
|
||||
settings = self.new_settings()
|
||||
settings = new_settings()
|
||||
settings.add_bookmark(bookmark['path'], bookmark['name'])
|
||||
settings.save()
|
||||
|
||||
settings = self.new_settings()
|
||||
settings = new_settings()
|
||||
bookmarks = settings.bookmarks
|
||||
self.assertEqual(len(settings.bookmarks), 0)
|
||||
self.assertFalse(bookmark in bookmarks)
|
||||
|
||||
def test_rename_bookmark(self):
|
||||
settings = self.new_settings()
|
||||
settings = new_settings()
|
||||
settings.add_bookmark('/tmp/repo', 'a')
|
||||
settings.add_bookmark('/tmp/repo', 'b')
|
||||
settings.add_bookmark('/tmp/repo', 'c')
|
||||
|
||||
Reference in New Issue
Block a user