Exemple #1
0
 def test_basic(self):
     def func(bar=False):
         return bar
     cases = [([], False), (['-b'], True)]
     for cs in cases:
         ret = rf.run(func, self.help(), argv=cs[0], check=False)
         self.assertEqual(ret, cs[1])
Exemple #2
0
 def test_lambda(self):
     func = lambda foo, bar=False: (foo, bar)
     cases = [
         (['2'], (2, False)),
         (['-b', '3'], (3, True)),
         (['4', '--bar'], (4, True))
     ]
     for cs in cases:
         ret = rf.run(func, self.help(), argv=cs[0], check=False)
         self.assertEqual(ret, cs[1])
Exemple #3
0
 def test_callable_object(self):
     class Func(object):
         def __call__(self, foo, bar=None):
             return (foo, bar)
     cases = [
         (['2'], (2, None)),
         (['-b', '3'], (3, True)),
         (['4', '--bar'], (4, True))
     ]
     for cs in cases:
         ret = rf.run(Func(), self.help(), argv=cs[0], check=False)
         self.assertEqual(ret, cs[1])
Exemple #4
0
 def test_class(self):
     class Func(object):
         def __init__(self, foo, bar=None):
             self.data = (foo, bar)
     cases = [
         (['2'], (2, None)),
         (['-b', '3'], (3, True)),
         (['4', '--bar'], (4, True))
     ]
     for cs in cases:
         ret = rf.run(Func, self.help(), argv=cs[0], check=False)
         self.assertEqual(ret.data, cs[1])
Exemple #5
0
#
# This file is part of the run package released under the BSD license.
#
import sys
import runfunc as rf

class Help(rf.Help):
    """\
    This is a blurb about this program. Its very entertaining to
    watch and think about what we might do with it.

        Look ma. Formatted text.

    And stuff
    """
    usage   = "%prog [options] value"

    value = rf.Check(int, "A value to multiply.")
    factor = rf.Check(float, "A factor by which to multiply.", opt='f')
    random = rf.Stream("r", "An input file to read from.", opt='r')
    verbose = rf.Flag("Multiply verbosely.", opt='v')

def main(value, factor=2.0, random=sys.stdin, verbose=False):
    newval = value * factor
    if verbose:
        print "%d * %s = %s" % (value, factor, newval)
    else:
        print newval

rf.run(main, Help())
Exemple #6
0
import sys
import runfunc as rf


class Help(rf.Help):
    """\
    This is a blurb about this program. Its very entertaining to
    watch and think about what we might do with it.

        Look ma. Formatted text.

    And stuff
    """
    usage = "%prog [options] value"

    value = rf.Check(int, "A value to multiply.")
    factor = rf.Check(float, "A factor by which to multiply.", opt='f')
    random = rf.Stream("r", "An input file to read from.", opt='r')
    verbose = rf.Flag("Multiply verbosely.", opt='v')


def main(value, factor=2.0, random=sys.stdin, verbose=False):
    newval = value * factor
    if verbose:
        print "%d * %s = %s" % (value, factor, newval)
    else:
        print newval


rf.run(main, Help())
Exemple #7
0
 def test_no_run(self):
     class Help(rf.Help):
         pass
     def func():
         return 10
     self.assertEqual(rf.run(func, Help()), None)