diff --git a/tests/CLITest.py b/tests/CLITest.py index 332edb8bf..6c24e771a 100644 --- a/tests/CLITest.py +++ b/tests/CLITest.py @@ -1,6 +1,6 @@ import unittest -from PyOpenWorm.command_util import SubCommand +from PyOpenWorm.command_util import SubCommand, IVar from PyOpenWorm.cli_command_wrapper import CLICommandWrapper from six import StringIO from contextlib import contextmanager @@ -100,6 +100,36 @@ def __init__(self): self.assertEqual(a.i, 1) + def test_ivar_default_str(self): + class A(object): + p = IVar(3) + a = A() + cm = CLICommandWrapper(a) + parser = cm.parser() + with noexit(), stdout() as out: + parser.parse_args(['sc', '--help']) + self.assertIn('3', out.getvalue()) + + def test_ivar_default_append(self): + class A(object): + p = IVar(3, doc='TEST_STRING') + a = A() + cm = CLICommandWrapper(a) + parser = cm.parser() + with noexit(), stdout() as out: + parser.parse_args(['sc', '--help']) + self.assertIn('3', out.getvalue()) + + def test_ivar_default_append_doc(self): + class A(object): + p = IVar(3, doc='TEST_STRING') + a = A() + cm = CLICommandWrapper(a) + parser = cm.parser() + with noexit(), stdout() as out: + parser.parse_args(['sc', '--help']) + self.assertIn('TEST_STRING', out.getvalue()) + @contextmanager def noexit(): diff --git a/tests/CommandTest.py b/tests/CommandTest.py index 810c9be1b..71fe4cb6f 100644 --- a/tests/CommandTest.py +++ b/tests/CommandTest.py @@ -12,7 +12,7 @@ from pytest import mark import git -from PyOpenWorm.git_repo import GitRepoProvider +from PyOpenWorm.git_repo import GitRepoProvider, _CloneProgress from PyOpenWorm.command import POW, UnreadableGraphException from PyOpenWorm.command_util import IVar, PropertyIVar @@ -178,12 +178,19 @@ def p(self): return 0 self.assertEqual('this', A.p.__doc__) + def test_ivar_default(self): + class A(object): + p = IVar(3) + + self.assertEqual(A().p, 3) + class IVarPropertyTest(unittest.TestCase): def test_set_setter(self): iv = PropertyIVar() iv.value_setter = lambda target, val: None + class A(object): p = iv a = A() @@ -191,6 +198,7 @@ class A(object): def test_set_setter2(self): iv = PropertyIVar() + class A(object): p = iv a = A() @@ -198,8 +206,6 @@ class A(object): a.p = 3 - - @mark.inttest class GitCommandTest(BaseTest): @@ -322,5 +328,37 @@ def _add_to_graph(self): self.cut.add_graph("http://example.org/ImAGraphYesSiree") +class CloneProgressTest(unittest.TestCase): + def setUp(self): + self.pr = Mock() + self.pr.n = 0 + self.cp = _CloneProgress(self.pr) + + def test_progress(self): + self.cp(1, 10) + self.pr.update.assert_called_with(10) + + def test_progress_reset(self): + self.pr.n = 3 + self.cp(2, 10) + self.pr.update.assert_called_with(10) + + def test_progress_not_reset(self): + self.pr.n = 5 + self.cp(0, 10) + self.pr.update.assert_called_with(5) + + def test_progress_total(self): + self.cp(0, 1, 11) + self.assertEqual(self.pr.total, 11) + + def test_progress_no_unit(self): + def f(): + raise AttributeError() + pr = Mock() + pr.unit.side_effect = f + _CloneProgress(pr) + + class _TestException(Exception): pass