Skip to content

Commit

Permalink
Use pypi:repeated_test
Browse files Browse the repository at this point in the history
  • Loading branch information
epsy committed Feb 8, 2016
1 parent 2dfd29c commit 6438295
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 255 deletions.
36 changes: 16 additions & 20 deletions clize/tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# COPYING for details.

from datetime import datetime
import unittest
import tempfile
import shutil
import os
Expand All @@ -12,12 +11,11 @@
from sigtools import support, modifiers

from clize import parser, errors, converters
from clize.tests import util
from clize.tests.util import Fixtures


@util.repeated_test
class ConverterRepTests(object):
def _test_func(self, conv, rep):
class ConverterRepTests(Fixtures):
def _test(self, conv, rep):
sig = support.s('*, par: c', locals={'c': conv})
csig = parser.CliSignature.from_signature(sig)
self.assertEqual(str(csig), rep)
Expand All @@ -26,19 +24,18 @@ def _test_func(self, conv, rep):
file = converters.file(), '--par=FILE'


@util.repeated_test
class ConverterTests(object):
def _test_func(self, conv, inp, out):
class ConverterTests(Fixtures):
def _test(self, conv, inp, out):
sig = support.s('*, par: c', locals={'c': conv})
csig = parser.CliSignature.from_signature(sig)
ba = util.read_arguments(csig, ['--par', inp])
ba = self.read_arguments(csig, ['--par', inp])
self.assertEqual(out, ba.kwargs['par'])

dt_jan1 = (
converters.datetime, '2014-01-01 12:00', datetime(2014, 1, 1, 12, 0))


class FileConverterTests(unittest.TestCase):
class FileConverterTests(Fixtures):
def setUp(self):
self.temp = tempfile.mkdtemp()

Expand All @@ -48,7 +45,7 @@ def tearDown(self):
def run_conv(self, conv, path):
sig = support.s('*, par: c', locals={'c': conv})
csig = parser.CliSignature.from_signature(sig)
ba = util.read_arguments(csig, ['--par', path])
ba = self.read_arguments(csig, ['--par', path])
return ba.kwargs['par']

def test_ret_type(self):
Expand All @@ -66,7 +63,7 @@ def func(afile):
self.assertEqual(f.name, path)
self.assertEqual(f.mode, 'r')
self.assertTrue(f.closed)
o, e = util.run(func, ['test', path])
o, e = self.crun(func, ['test', path])
self.assertFalse(o.getvalue())
self.assertFalse(e.getvalue())

Expand All @@ -80,7 +77,7 @@ def func(afile):
self.assertEqual(f.mode, 'w')
self.assertTrue(f.closed)
self.assertTrue(os.path.exists(path))
o, e = util.run(func, ['test', path])
o, e = self.crun(func, ['test', path])
self.assertFalse(o.getvalue())
self.assertFalse(e.getvalue())

Expand All @@ -91,7 +88,7 @@ def test_file_missing(self):
@modifiers.annotate(afile=converters.file())
def func(afile):
raise NotImplementedError
stdout, stderr = util.run(func, ['test', path])
stdout, stderr = self.crun(func, ['test', path])
self.assertFalse(stdout.getvalue())
self.assertTrue(stderr.getvalue().startswith(
'test: Bad value for afile: File does not exist: '))
Expand All @@ -103,7 +100,7 @@ def test_dir_missing(self):
@modifiers.annotate(afile=converters.file(mode='w'))
def func(afile):
raise NotImplementedError
stdout, stderr = util.run(func, ['test', path])
stdout, stderr = self.crun(func, ['test', path])
self.assertFalse(stdout.getvalue())
self.assertTrue(stderr.getvalue().startswith(
'test: Bad value for afile: Directory does not exist: '))
Expand Down Expand Up @@ -131,18 +128,17 @@ def func(afile):
os.chmod(path, stat.S_IRUSR)
with afile:
raise NotImplementedError
stdout, stderr = util.run(func, ['test', path])
stdout, stderr = self.crun(func, ['test', path])
self.assertFalse(stdout.getvalue())
self.assertTrue(stderr.getvalue().startswith(
'test: Permission denied: '))


@util.repeated_test
class ConverterErrorTests(object):
def _test_func(self, conv, inp):
class ConverterErrorTests(Fixtures):
def _test(self, conv, inp):
sig = support.s('*, par: c', locals={'c': conv})
csig = parser.CliSignature.from_signature(sig)
self.assertRaises(errors.BadArgumentFormat,
util.read_arguments, csig, ['--par', inp])
self.read_arguments, csig, ['--par', inp])

dt_baddate = converters.datetime, 'not a date'
26 changes: 11 additions & 15 deletions clize/tests/test_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
from sigtools.wrappers import wrapper_decorator

from clize import runner, help, parser, util
from clize.tests.util import repeated_test
from clize.tests.util import Fixtures

USAGE_HELP = 'func --help [--usage]'

@repeated_test
class WholeHelpTests(object):
def _test_func(self, sig, doc, usage, help_str):

class WholeHelpTests(Fixtures):
def _test(self, sig, doc, usage, help_str):
func = f(sig, pre="from clize import Parameter as P")
func.__doc__ = doc
r = runner.Clize(func)
Expand Down Expand Up @@ -349,7 +349,7 @@ def _do_test(self, runner, usage, help_str):
Footer
"""
undocumented = "one:P.U, two:P.U, *args:P.U, alpha:P.U, beta:P.U", """
undocumented_all = "one:P.U, two:P.U, *args:P.U, alpha:P.U, beta:P.U", """
Description
two: unseen
Expand Down Expand Up @@ -443,9 +443,8 @@ def show_help(self, desc, after, f, cols):



@repeated_test
class WrappedFuncTests(object):
def _test_func(self, sig, wrapper_sigs, doc, wrapper_docs, help_str):
class WrappedFuncTests(Fixtures):
def _test(self, sig, wrapper_sigs, doc, wrapper_docs, help_str):
ifunc = f(sig, pre="from clize import Parameter")
ifunc.__doc__ = doc
func = ifunc
Expand Down Expand Up @@ -590,9 +589,8 @@ def _test_func(self, sig, wrapper_sigs, doc, wrapper_docs, help_str):
"""


@repeated_test
class FormattingTests(object):
def _test_func(self, sig, doc, help_str):
class FormattingTests(Fixtures):
def _test(self, sig, doc, help_str):
try:
backw = util.get_terminal_width
except AttributeError:
Expand Down Expand Up @@ -703,9 +701,8 @@ def _test_func(self, sig, doc, help_str):
)


@repeated_test
class DispatcherHelper(object):
def _test_func(self, description, footer, sigs, docs, usage, help_str):
class DispatcherHelper(Fixtures):
def _test(self, description, footer, sigs, docs, usage, help_str):
funcs = []
for i, sig, doc in zip(count(1), sigs, docs):
func = f(sig)
Expand Down Expand Up @@ -833,4 +830,3 @@ def func():
ext
func
""")

0 comments on commit 6438295

Please sign in to comment.