From 16697616a1580db11a171d1eff370975733227d7 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 17 Jul 2021 11:59:32 -0700 Subject: [PATCH] tests: remove #! lines and leverage pytest further Signed-off-by: David Aguilar --- test/app_test.py | 46 ++--- test/branch_test.py | 412 ++++++++++++++++++++++++------------------ test/cmds_test.py | 9 - test/compat_test.py | 46 ++--- test/core_test.py | 122 ++++++------- test/dag_test.py | 2 +- test/diffparse_test.py | 5 +- test/display_test.py | 7 - test/git_test.py | 5 - test/gitcfg_test.py | 5 - test/gitcmds_test.py | 5 - test/gitops_test.py | 7 +- test/gravatar_test.py | 5 - test/helper.py | 6 +- test/i18n_test.py | 4 - test/icons_test.py | 34 ++-- test/main_model_test.py | 5 - test/models_selection_test.py | 40 ++-- test/resources_test.py | 5 - test/settings_test.py | 4 - test/spellcheck_test.py | 51 +++--- test/textwrap_test.py | 8 +- test/utils_test.py | 6 - 23 files changed, 398 insertions(+), 441 deletions(-) rewrite test/app_test.py (86%) rewrite test/branch_test.py (83%) rewrite test/compat_test.py (80%) rewrite test/core_test.py (92%) rewrite test/icons_test.py (75%) rewrite test/models_selection_test.py (77%) rewrite test/spellcheck_test.py (80%) diff --git a/test/app_test.py b/test/app_test.py dissimilarity index 86% index d5413106..6c68ac50 100644 --- a/test/app_test.py +++ b/test/app_test.py @@ -1,29 +1,17 @@ -#!/usr/bin/env python -from __future__ import absolute_import, division, unicode_literals -import argparse -import unittest - -from cola import app - -from .helper import run_unittest - - -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) - - -def test_suite(): - return unittest.makeSuite(AppTestCase) - - -if __name__ == "__main__": - run_unittest(test_suite()) +from __future__ import absolute_import, division, unicode_literals +import argparse + +from cola import app + + +def test_setup_environment(): + # If the function doesn't throw an exception we are happy. + assert hasattr(app, 'setup_environment') + app.setup_environment() + + +def test_add_common_arguments(): + # If the function doesn't throw an exception we are happy. + parser = argparse.ArgumentParser() + assert hasattr(app, 'add_common_arguments') + app.add_common_arguments(parser) diff --git a/test/branch_test.py b/test/branch_test.py dissimilarity index 83% index b93ceaf1..a6a3b517 100644 --- a/test/branch_test.py +++ b/test/branch_test.py @@ -1,171 +1,241 @@ -#!/usr/bin/env python -from __future__ import absolute_import, division, unicode_literals -import unittest - -try: - from unittest.mock import MagicMock -except ImportError: - from mock import MagicMock - -from cola.widgets import branch - - -class BranchesTestCase(unittest.TestCase): - """Tests related to the branches widget""" - - def test_create_tree_entries(self): - names = [ - 'abc', - 'cat/abc', - 'cat/def', - 'xyz/xyz', - ] - root = branch.create_tree_entries(names) - self.assertEqual(3, len(root.children)) - # 'abc' - abc = root.children[0] - self.assertEqual('abc', abc.basename) - self.assertEqual('abc', abc.refname) - self.assertEqual([], abc.children) - # 'cat' - cat = root.children[1] - self.assertEqual('cat', cat.basename) - self.assertEqual(None, cat.refname) - self.assertEqual(2, len(cat.children)) - # 'cat/abc' - cat_abc = cat.children[0] - self.assertEqual('abc', cat_abc.basename) - self.assertEqual('cat/abc', cat_abc.refname) - self.assertEqual([], cat_abc.children) - # 'cat/def' - cat_def = cat.children[1] - self.assertEqual('def', cat_def.basename) - self.assertEqual('cat/def', cat_def.refname) - self.assertEqual([], cat_def.children) - # 'xyz' - xyz = root.children[2] - self.assertEqual('xyz', xyz.basename) - self.assertEqual(None, xyz.refname) - self.assertEqual(1, len(xyz.children)) - # 'xyz/xyz' - xyz_xyz = xyz.children[0] - self.assertEqual('xyz', xyz_xyz.basename) - self.assertEqual('xyz/xyz', xyz_xyz.refname) - self.assertEqual([], xyz_xyz.children) - - def test_create_name_dict(self): - """Test transforming unix path-like names into a nested dict""" - branches = [ - 'top_1/child_1/child_1_1', - 'top_1/child_1/child_1_2', - 'top_1/child_2/child_2_1/child_2_1_1', - 'top_1/child_2/child_2_1/child_2_1_2', - ] - result = branch.create_name_dict(branches) - inner_child = {'child_2_1_2': {}, 'child_2_1_1': {}} - self.assertEqual( - { - 'top_1': { - 'child_1': {'child_1_2': {}, 'child_1_1': {}}, - 'child_2': {'child_2_1': inner_child}, - } - }, - result, - ) - - def test_create_toplevel_item(self): - names = [ - 'child_1', - 'child_2/child_2_1', - 'child_2/child_2_2', - ] - tree = branch.create_tree_entries(names) - tree.basename = 'top' - result = branch.create_toplevel_item(tree) - self.assertEqual('top', result.name) - self.assertEqual(2, result.childCount()) - self.assertEqual('child_1', result.child(0).name) - self.assertEqual('child_1', result.child(0).refname) - self.assertEqual('child_2', result.child(1).name) - self.assertEqual(None, result.child(1).refname) - self.assertEqual(2, result.child(1).childCount()) - self.assertEqual('child_2_1', result.child(1).child(0).name) - self.assertEqual('child_2_2', result.child(1).child(1).name) - self.assertEqual('child_2/child_2_1', result.child(1).child(0).refname) - self.assertEqual('child_2/child_2_2', result.child(1).child(1).refname) - - def test_get_toplevel_item(self): - items = _create_top_item() - result = branch.get_toplevel_item(items['child_1']) - self.assertTrue(items['top'] is result) - - result = branch.get_toplevel_item(items['sub_child_2_1']) - self.assertTrue(items['top'] is result) - - def test_refname_attribute(self): - items = _create_top_item() - - result = items['child_1'].refname - self.assertEqual('child_1', result) - - result = items['sub_child_2_2'].refname - self.assertEqual('child_2/sub_child_2_2', result) - - def test_should_return_a_valid_child_on_find_child(self): - """Test the find_child function.""" - items = _create_top_item() - child = branch.find_by_refname(items['top'], 'child_1') - self.assertEqual('child_1', child.refname) - - child = branch.find_by_refname(items['top'], 'child_2/sub_child_2_2') - self.assertEqual('sub_child_2_2', child.name) - - def test_should_return_empty_state_on_save_state(self): - """Test the save_state function.""" - top = _create_item('top', None, False) - tree_helper = branch.BranchesTreeHelper() - result = tree_helper.save_state(top) - self.assertEqual({'top': {}}, result) - - def test_should_return_a_valid_state_on_save_state(self): - """Test the save_state function.""" - items = _create_top_item() - tree_helper = branch.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_top_item(): - top = _create_item('top', None, True) - child_1 = _create_item('child_1', 'child_1', False) - child_2 = _create_item('child_2', None, True) - sub_child_2_1 = _create_item('sub_child_2_1', 'child_2/sub_child_2_1', False) - sub_child_2_2 = _create_item('sub_child_2_2', 'child_2/sub_child_2_2', False) - - 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, - } - - -def _create_item(name, refname, expanded): - item = branch.BranchTreeWidgetItem(name, refname=refname) - item.isExpanded = MagicMock(return_value=expanded) - return item - - -if __name__ == '__main__': - unittest.main() +"""Tests related to the branches widget""" +from __future__ import absolute_import, division, unicode_literals + +try: + from unittest.mock import MagicMock +except ImportError: + from mock import MagicMock + +from cola.widgets import branch + + +def test_create_tree_entries(): + names = [ + 'abc', + 'cat/abc', + 'cat/def', + 'xyz/xyz', + ] + root = branch.create_tree_entries(names) + expect = 3 + actual = len(root.children) + assert expect == actual + + # 'abc' + abc = root.children[0] + expect = 'abc' + actual = abc.basename + assert expect == actual + expect = 'abc' + actual = abc.refname + assert expect == actual + expect = [] + actual = abc.children + assert expect == actual + + # 'cat' + cat = root.children[1] + expect = 'cat' + actual = 'cat' + assert expect == actual + assert cat.refname is None + expect = 2 + actual = len(cat.children) + assert expect == actual + + # 'cat/abc' + cat_abc = cat.children[0] + expect = 'abc' + actual = cat_abc.basename + assert expect == actual + expect = 'cat/abc' + actual = cat_abc.refname + assert expect == actual + expect = [] + actual = cat_abc.children + assert expect == actual + + # 'cat/def' + cat_def = cat.children[1] + expect = 'def' + actual = cat_def.basename + assert expect == actual + expect = 'cat/def' + actual = cat_def.refname + assert expect == actual + expect = [] + actual = cat_def.children + assert expect == actual + + # 'xyz' + xyz = root.children[2] + expect = 'xyz' + actual = xyz.basename + assert expect == actual + assert xyz.refname is None + expect = 1 + actual = len(xyz.children) + assert expect == actual + + # 'xyz/xyz' + xyz_xyz = xyz.children[0] + expect = 'xyz' + actual = xyz_xyz.basename + assert expect == actual + + expect = 'xyz/xyz' + actual = xyz_xyz.refname + assert expect == actual + + expect = [] + actual = xyz_xyz.children + assert expect == actual + + +def test_create_name_dict(): + """Test transforming unix path-like names into a nested dict""" + branches = [ + 'top_1/child_1/child_1_1', + 'top_1/child_1/child_1_2', + 'top_1/child_2/child_2_1/child_2_1_1', + 'top_1/child_2/child_2_1/child_2_1_2', + ] + inner_child = {'child_2_1_2': {}, 'child_2_1_1': {}} + expect = { + 'top_1': { + 'child_1': {'child_1_2': {}, 'child_1_1': {}}, + 'child_2': {'child_2_1': inner_child}, + } + } + actual = branch.create_name_dict(branches) + assert expect == actual + + +def test_create_toplevel_item(): + names = [ + 'child_1', + 'child_2/child_2_1', + 'child_2/child_2_2', + ] + tree = branch.create_tree_entries(names) + tree.basename = 'top' + top = branch.create_toplevel_item(tree) + + expect = 'top' + actual = top.name + assert expect == actual + + expect = 2 + actual = top.childCount() + assert expect == actual + + expect = 'child_1' + actual = top.child(0).name + assert expect == actual + + expect = 'child_1' + actual = top.child(0).refname + assert expect == actual + + expect = 'child_2' + actual = top.child(1).name + assert expect == actual + + assert top.child(1).refname is None + + expect = 2 + actual = top.child(1).childCount() + assert expect == actual + + expect = 'child_2_1' + actual = top.child(1).child(0).name + assert expect == actual + + expect = 'child_2_2' + actual = top.child(1).child(1).name + assert expect == actual + + expect = 'child_2/child_2_1' + actual = top.child(1).child(0).refname + assert expect == actual + + expect = 'child_2/child_2_2' + actual = top.child(1).child(1).refname + assert expect == actual + + +def test_get_toplevel_item(): + items = _create_top_item() + actual = branch.get_toplevel_item(items['child_1']) + assert items['top'] is actual + + actual = branch.get_toplevel_item(items['sub_child_2_1']) + assert items['top'] is actual + + +def test_refname_attribute(): + items = _create_top_item() + + actual = items['child_1'].refname + expect = 'child_1' + assert expect == actual + + actual = items['sub_child_2_2'].refname + expect = 'child_2/sub_child_2_2' + assert expect == actual + + +def test_should_return_a_valid_child_on_find_child(): + """Test the find_child function.""" + items = _create_top_item() + child = branch.find_by_refname(items['top'], 'child_1') + assert child.refname == 'child_1' + + child = branch.find_by_refname(items['top'], 'child_2/sub_child_2_2') + assert child.name == 'sub_child_2_2' + + +def test_should_return_empty_state_on_save_state(): + """Test the save_state function.""" + top = _create_item('top', None, False) + tree_helper = branch.BranchesTreeHelper() + actual = tree_helper.save_state(top) + assert {'top': {}} == actual + + +def test_should_return_a_valid_state_on_save_state(): + """Test the save_state function.""" + items = _create_top_item() + tree_helper = branch.BranchesTreeHelper() + actual = tree_helper.save_state(items['top']) + expect = { + 'top': { + 'child_1': {}, + 'child_2': {'sub_child_2_1': {}, 'sub_child_2_2': {}}, + } + } + assert expect == actual + + +def _create_top_item(): + top = _create_item('top', None, True) + child_1 = _create_item('child_1', 'child_1', False) + child_2 = _create_item('child_2', None, True) + sub_child_2_1 = _create_item('sub_child_2_1', 'child_2/sub_child_2_1', False) + sub_child_2_2 = _create_item('sub_child_2_2', 'child_2/sub_child_2_2', False) + + 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, + } + + +def _create_item(name, refname, expanded): + item = branch.BranchTreeWidgetItem(name, refname=refname) + item.isExpanded = MagicMock(return_value=expanded) + return item diff --git a/test/cmds_test.py b/test/cmds_test.py index 5313d80f..255f28c5 100644 --- a/test/cmds_test.py +++ b/test/cmds_test.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python """Test the cmds module""" from __future__ import absolute_import, division, unicode_literals @@ -7,15 +6,12 @@ try: except ImportError: from mock import Mock, patch -import pytest - from cola import cmds from cola.compat import uchr def test_Commit_strip_comments(): """Ensure that commit messages are stripped of comments""" - msg = 'subject\n\n#comment\nbody' expect = 'subject\n\nbody\n' actual = cmds.Commit.strip_comments(msg) @@ -24,7 +20,6 @@ def test_Commit_strip_comments(): def test_commit_strip_comments_unicode(): """Ensure that unicode is preserved in stripped commit messages""" - msg = uchr(0x1234) + '\n\n#comment\nbody' expect = uchr(0x1234) + '\n\nbody\n' actual = cmds.Commit.strip_comments(msg) @@ -227,7 +222,3 @@ def test_undo_last_commit_confirms_action(prefs, interaction): assert cmd.confirm() context.model.is_commit_published.assert_called_once() interaction.confirm.assert_called_once() - - -if __name__ == '__main__': - pytest.main([__file__]) diff --git a/test/compat_test.py b/test/compat_test.py dissimilarity index 80% index a82230d2..c94b5e34 100644 --- a/test/compat_test.py +++ b/test/compat_test.py @@ -1,27 +1,19 @@ -#!/usr/bin/env python -# encoding: utf-8 -from __future__ import absolute_import, division, unicode_literals -import os -import unittest - -from cola import compat - - -class CompatTestCase(unittest.TestCase): - """Tests the compat module""" - - def test_setenv(self): - """Test the core.decode function""" - key = 'COLA_UNICODE_TEST' - value = '字龍' - compat.setenv(key, value) - self.assertTrue(key in os.environ) - self.assertTrue(os.getenv(key)) - - compat.unsetenv(key) - self.assertFalse(key in os.environ) - self.assertFalse(os.getenv(key)) - - -if __name__ == '__main__': - unittest.main() +"""Tests the compat module""" +# encoding: utf-8 +from __future__ import absolute_import, division, unicode_literals +import os + +from cola import compat + + +def test_setenv(): + """Test the core.decode function""" + key = 'COLA_UNICODE_TEST' + value = '字龍' + compat.setenv(key, value) + assert key in os.environ + assert os.getenv(key) + + compat.unsetenv(key) + assert key not in os.environ + assert not os.getenv(key) diff --git a/test/core_test.py b/test/core_test.py dissimilarity index 92% index 9c05e25c..e4a553af 100644 --- a/test/core_test.py +++ b/test/core_test.py @@ -1,62 +1,60 @@ -#!/usr/bin/env python -# encoding: utf-8 -from __future__ import absolute_import, division, unicode_literals -import unittest - -from cola import core - -from . import helper - - -class CoreColaUnicodeTestCase(unittest.TestCase): - """Tests the cola.core module's unicode handling""" - - def test_core_decode(self): - """Test the core.decode function""" - filename = helper.fixture('unicode.txt') - expect = core.decode(core.encode('unicøde')) - actual = core.read(filename).strip() - self.assertEqual(expect, actual) - - def test_core_encode(self): - """Test the core.encode function""" - filename = helper.fixture('unicode.txt') - expect = core.encode('unicøde') - actual = core.encode(core.read(filename).strip()) - self.assertEqual(expect, actual) - - def test_decode_None(self): - """Ensure that decode(None) returns None""" - expect = None - actual = core.decode(None) - self.assertEqual(expect, actual) - - def test_decode_utf8(self): - filename = helper.fixture('cyrillic-utf-8.txt') - actual = core.read(filename) - self.assertEqual(actual.encoding, 'utf-8') - - def test_decode_non_utf8(self): - filename = helper.fixture('cyrillic-cp1251.txt') - actual = core.read(filename) - self.assertEqual(actual.encoding, 'iso-8859-15') - - def test_decode_non_utf8_string(self): - filename = helper.fixture('cyrillic-cp1251.txt') - with open(filename, 'rb') as f: - content = f.read() - actual = core.decode(content) - self.assertEqual(actual.encoding, 'iso-8859-15') - - def test_guess_mimetype(self): - value = '字龍.txt' - expect = 'text/plain' - actual = core.guess_mimetype(value) - self.assertEqual(expect, actual) - # This function is robust to bytes vs. unicode - actual = core.guess_mimetype(core.encode(value)) - self.assertEqual(expect, actual) - - -if __name__ == '__main__': - unittest.main() +"""Tests the cola.core module's unicode handling""" +# encoding: utf-8 +from __future__ import absolute_import, division, unicode_literals + +from cola import core + +from . import helper + + +def test_core_decode(): + """Test the core.decode function""" + filename = helper.fixture('unicode.txt') + expect = core.decode(core.encode('unicøde')) + actual = core.read(filename).strip() + assert expect == actual + + +def test_core_encode(): + """Test the core.encode function""" + filename = helper.fixture('unicode.txt') + expect = core.encode('unicøde') + actual = core.encode(core.read(filename).strip()) + assert expect == actual + + +def test_decode_None(): + """Ensure that decode(None) returns None""" + expect = None + actual = core.decode(None) + assert expect == actual + + +def test_decode_utf8(): + filename = helper.fixture('cyrillic-utf-8.txt') + actual = core.read(filename) + assert actual.encoding == 'utf-8' + + +def test_decode_non_utf8(): + filename = helper.fixture('cyrillic-cp1251.txt') + actual = core.read(filename) + assert actual.encoding == 'iso-8859-15' + + +def test_decode_non_utf8_string(): + filename = helper.fixture('cyrillic-cp1251.txt') + with open(filename, 'rb') as f: + content = f.read() + actual = core.decode(content) + assert actual.encoding == 'iso-8859-15' + + +def test_guess_mimetype(): + value = '字龍.txt' + expect = 'text/plain' + actual = core.guess_mimetype(value) + assert expect == actual + # This function is robust to bytes vs. unicode + actual = core.guess_mimetype(core.encode(value)) + assert expect == actual diff --git a/test/dag_test.py b/test/dag_test.py index c5179647..520dae84 100644 --- a/test/dag_test.py +++ b/test/dag_test.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python """Tests DAG functionality""" from __future__ import absolute_import, division, unicode_literals @@ -26,6 +25,7 @@ f4fb8fd5baaa55d9b41faca79be289bb4407281e^Ae3f5a2d0248de6197d6e0e63c901810b8a9af2 class DAGTestCase(helper.GitRepositoryTestCase): + def setUp(self): helper.GitRepositoryTestCase.setUp(self) self.params = dag.DAG('HEAD', 1000) diff --git a/test/diffparse_test.py b/test/diffparse_test.py index d0791ec9..9abc5e92 100644 --- a/test/diffparse_test.py +++ b/test/diffparse_test.py @@ -8,6 +8,7 @@ from . import helper class ParseDiffTestCase(unittest.TestCase): + def test_diff(self): fixture_path = helper.fixture('diff.txt') parser = diffparse.DiffParser('cola/diffparse.py', core.read(fixture_path)) @@ -374,7 +375,3 @@ class ParseRangeStrTestCase(unittest.TestCase): start, count = diffparse.parse_range_str('0,0') self.assertEqual(start, 0) self.assertEqual(count, 0) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/display_test.py b/test/display_test.py index 95220fc1..531d999a 100644 --- a/test/display_test.py +++ b/test/display_test.py @@ -1,8 +1,5 @@ -#!/usr/bin/env python from __future__ import absolute_import, division, unicode_literals -import pytest - from cola import display @@ -29,7 +26,3 @@ def test_normalize_path(): expect = 'C:/games/doom2' actual = display.normalize_path(path) assert expect == actual - - -if __name__ == '__main__': - pytest.main([__file__]) diff --git a/test/git_test.py b/test/git_test.py index 858a60c5..1427e647 100644 --- a/test/git_test.py +++ b/test/git_test.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python """Tests various operations using the cola.git module """ from __future__ import absolute_import, division, unicode_literals @@ -371,7 +370,3 @@ class GitCommandTest(unittest.TestCase): self.assertEqual(status, 0) self.assertEqual(out, '\0' * (1024 * 16 + 1)) self.assertEqual(err, '\0' * (1024 * 16 + 1)) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/gitcfg_test.py b/test/gitcfg_test.py index f0dc2c2c..11cc7bf5 100644 --- a/test/gitcfg_test.py +++ b/test/gitcfg_test.py @@ -1,5 +1,4 @@ from __future__ import absolute_import, division, unicode_literals -import unittest from . import helper @@ -120,7 +119,3 @@ class GitConfigTestCase(helper.GitRepositoryTestCase): expect = '/test/hooks-lowercase/example' actual = self.cfg.hooks_path('example') assert expect == actual - - -if __name__ == '__main__': - unittest.main() diff --git a/test/gitcmds_test.py b/test/gitcmds_test.py index aec062b0..8df6dc82 100644 --- a/test/gitcmds_test.py +++ b/test/gitcmds_test.py @@ -1,6 +1,5 @@ from __future__ import absolute_import, division, unicode_literals import os -import unittest from cola import gitcmds from cola.widgets.remote import get_default_remote @@ -206,7 +205,3 @@ class GitCmdsTestCase(helper.GitRepositoryTestCase): self.run_git('add', 'A') actual = gitcmds.diff_helper(self.context, ref='HEAD', cached=True) assert '+A change\n' in actual - - -if __name__ == '__main__': - unittest.main() diff --git a/test/gitops_test.py b/test/gitops_test.py index 42990f85..e059205d 100644 --- a/test/gitops_test.py +++ b/test/gitops_test.py @@ -1,12 +1,11 @@ -#!/usr/bin/env python """Tests basic git operations: commit, log, config""" from __future__ import absolute_import, division, unicode_literals -import unittest from . import helper class ColaBasicGitTestCase(helper.GitRepositoryTestCase): + def test_git_commit(self): """Test running 'git commit' via cola.git""" self.write_file('A', 'A') @@ -23,7 +22,3 @@ class ColaBasicGitTestCase(helper.GitRepositoryTestCase): self.run_git('config', 'section.key', 'value') value = self.git.config('section.key', get=True) self.assertEqual(value, (0, 'value', '')) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/gravatar_test.py b/test/gravatar_test.py index af372c18..9404c3dd 100644 --- a/test/gravatar_test.py +++ b/test/gravatar_test.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python from __future__ import absolute_import, division, unicode_literals import unittest @@ -19,7 +18,3 @@ class GravatarTestCase(unittest.TestCase): actual = gravatar.Gravatar.url_for_email(email, 64) self.assertEqual(expect, actual) self.assertTrue(isinstance(actual, ustr)) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/helper.py b/test/helper.py index c5e98fac..40b541c4 100644 --- a/test/helper.py +++ b/test/helper.py @@ -25,10 +25,6 @@ def fixture(*paths): return os.path.join(dirname, 'fixtures', *paths) -def run_unittest(suite): - return unittest.TextTestRunner(verbosity=2).run(suite) - - # shutil.rmtree() can't remove read-only files on Windows. This onerror # handler, adapted from , works # around this by changing such files to be writable and then re-trying. @@ -41,6 +37,8 @@ def remove_readonly(func, path, _exc_info): class TmpPathTestCase(unittest.TestCase): + """Run operations in a temporary directory""" + def setUp(self): self._testdir = tempfile.mkdtemp('_cola_test') os.chdir(self._testdir) diff --git a/test/i18n_test.py b/test/i18n_test.py index ba33cde3..324410f2 100644 --- a/test/i18n_test.py +++ b/test/i18n_test.py @@ -56,7 +56,3 @@ class ColaI18nTestCase(unittest.TestCase): expect = 'Pousser' actual = N_('Push') self.assertEqual(expect, actual) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/icons_test.py b/test/icons_test.py dissimilarity index 75% index 685ca9d6..c8d67101 100644 --- a/test/icons_test.py +++ b/test/icons_test.py @@ -1,19 +1,15 @@ -#!/usr/bin/env python -# encoding: utf-8 -from __future__ import absolute_import, division, unicode_literals -import unittest - -from cola import compat -from cola import core -from cola import icons - - -class IconTestCase(unittest.TestCase): - def test_from_filename_unicode(self): - filename = compat.uchr(0x400) + '.py' - expect = 'file-code.svg' - actual = icons.basename_from_filename(filename) - self.assertEqual(expect, actual) - - actual = icons.basename_from_filename(core.encode(filename)) - self.assertEqual(expect, actual) +from __future__ import absolute_import, division, unicode_literals + +from cola import compat +from cola import core +from cola import icons + + +def test_from_filename_unicode(): + filename = compat.uchr(0x400) + '.py' + expect = 'file-code.svg' + actual = icons.basename_from_filename(filename) + assert expect == actual + + actual = icons.basename_from_filename(core.encode(filename)) + assert expect == actual diff --git a/test/main_model_test.py b/test/main_model_test.py index 68f335a0..6e6066e1 100644 --- a/test/main_model_test.py +++ b/test/main_model_test.py @@ -1,5 +1,4 @@ from __future__ import absolute_import, division, unicode_literals - import os import unittest @@ -229,7 +228,3 @@ class RemoteArgsTestCase(unittest.TestCase): self.assertTrue(kwargs['verbose']) self.assertFalse('tags' in kwargs) self.assertFalse('rebase' in kwargs) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/models_selection_test.py b/test/models_selection_test.py dissimilarity index 77% index 474bcdf4..22fbb1a5 100644 --- a/test/models_selection_test.py +++ b/test/models_selection_test.py @@ -1,23 +1,17 @@ -from __future__ import absolute_import, division, unicode_literals -import unittest - -import mock - -from cola.models import selection - - -class SelectionTestCase(unittest.TestCase): - def test_union(self): - t = mock.Mock() - t.staged = ['a'] - t.unmerged = ['a', 'b'] - t.modified = ['b', 'a', 'c'] - t.untracked = ['d'] - - expect = ['a', 'b', 'c', 'd'] - actual = selection.union(t) - self.assertEqual(expect, actual) - - -if __name__ == '__main__': - unittest.main() +from __future__ import absolute_import, division, unicode_literals + +import mock + +from cola.models import selection + + +def test_union(): + t = mock.Mock() + t.staged = ['a'] + t.unmerged = ['a', 'b'] + t.modified = ['b', 'a', 'c'] + t.untracked = ['d'] + + expect = ['a', 'b', 'c', 'd'] + actual = selection.union(t) + assert expect == actual diff --git a/test/resources_test.py b/test/resources_test.py index 26917afb..d7fa6419 100644 --- a/test/resources_test.py +++ b/test/resources_test.py @@ -1,7 +1,6 @@ from __future__ import absolute_import, division, unicode_literals from mock import patch -import pytest from cola import resources from . import helper @@ -38,7 +37,3 @@ def test_command_win32(mock_prefix, mock_compat): expect = helper.fixture('bin', 'exe-cmd.exe') actual = resources.command('exe-cmd') assert expect == actual - - -if __name__ == '__main__': - pytest.main([__file__]) diff --git a/test/settings_test.py b/test/settings_test.py index 8b0e835d..03518ac6 100644 --- a/test/settings_test.py +++ b/test/settings_test.py @@ -80,7 +80,3 @@ class SettingsTestCase(unittest.TestCase): expect = ['a', 'test', 'c'] actual = [i['name'] for i in settings.bookmarks] self.assertEqual(expect, actual) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/spellcheck_test.py b/test/spellcheck_test.py dissimilarity index 80% index 97fbcffe..fd00080f 100644 --- a/test/spellcheck_test.py +++ b/test/spellcheck_test.py @@ -1,28 +1,23 @@ -#!/usr/bin/env python -from __future__ import absolute_import, division, unicode_literals -import unittest - -from cola import compat -from cola import spellcheck - -from . import helper - - -class TestCase(unittest.TestCase): - def test_spellcheck_generator(self): - check = spellcheck.NorvigSpellCheck() - self.assert_spellcheck(check) - - def test_spellcheck_unicode(self): - path = helper.fixture('unicode.txt') - check = spellcheck.NorvigSpellCheck(cracklib=path) - self.assert_spellcheck(check) - - def assert_spellcheck(self, check): - for word in check.read(): - self.assertTrue(word is not None) - self.assertTrue(isinstance(word, compat.ustr)) - - -if __name__ == '__main__': - unittest.main() +from __future__ import absolute_import, division, unicode_literals + +from cola import compat +from cola import spellcheck + +from . import helper + + +def test_spellcheck_generator(): + check = spellcheck.NorvigSpellCheck() + assert_spellcheck(check) + + +def test_spellcheck_unicode(): + path = helper.fixture('unicode.txt') + check = spellcheck.NorvigSpellCheck(cracklib=path) + assert_spellcheck(check) + + +def assert_spellcheck(check): + for word in check.read(): + assert word is not None + assert isinstance(word, compat.ustr) diff --git a/test/textwrap_test.py b/test/textwrap_test.py index 16d37271..d092415e 100644 --- a/test/textwrap_test.py +++ b/test/textwrap_test.py @@ -1,8 +1,6 @@ -#!/usr/bin/env python - from __future__ import absolute_import, division, unicode_literals - import unittest + from cola import textwrap @@ -185,7 +183,3 @@ Link: This also avoids word-wrap expect = 'xx0 xx1 xx2 xx3 xx4\nxx5 xx6 xx7 xx8 xx9\nxxa xxb' actual = textwrap.word_wrap(text, 8, 22) self.assertEqual(expect, actual) - - -if __name__ == '__main__': - unittest.main() diff --git a/test/utils_test.py b/test/utils_test.py index 1fc36366..7de48db5 100644 --- a/test/utils_test.py +++ b/test/utils_test.py @@ -1,6 +1,4 @@ -#!/usr/bin/env python from __future__ import absolute_import, division, unicode_literals - import os import unittest @@ -93,7 +91,3 @@ class ColaUtilsTestCase(unittest.TestCase): expect = '.' actual = utils.select_directory([filename, '.']) self.assertEqual(expect, actual) - - -if __name__ == '__main__': - unittest.main() -- 2.11.4.GIT