Skip to content

Commit

Permalink
Adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwatts15 committed Jun 17, 2018
1 parent a22cf1c commit b2d7efb
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
32 changes: 31 additions & 1 deletion tests/CLITest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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():
Expand Down
44 changes: 41 additions & 3 deletions tests/CommandTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -178,28 +178,34 @@ 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()
a.p = 3

def test_set_setter2(self):
iv = PropertyIVar()

class A(object):
p = iv
a = A()
with self.assertRaises(AttributeError):
a.p = 3




@mark.inttest
class GitCommandTest(BaseTest):

Expand Down Expand Up @@ -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

0 comments on commit b2d7efb

Please sign in to comment.