Exemplo n.º 1
0
def __test__(verbose=False):
    #-------------------------------------------------------------------------------
    """
    used for automated module testing. see L{tester}
    """
    import pylib.tester as tester

    c = Cache(3)
    c['a'] = 'a'
    c['b'] = 'b'
    c['c'] = 'c'
    c['a']
    c['d'] = 'd'
    tester.Assert(
        str(c) == str({
            u'a': (4, u'a'),
            u'c': (3, u'c'),
            u'd': (5, u'd')
        }))

    c['d'] = 'd'
    c['e'] = 'e'
    tester.Assert(
        str(c) == str({
            u'a': (4, u'a'),
            u'e': (7, u'e'),
            u'd': (6, u'd')
        }))

    return 0
Exemplo n.º 2
0
def __test__(verbose=False):
    #-------------------------------------------------------------------------------
    """
    used for automated module testing. see L{tester}
    """
    import pylib.tester as tester

    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    class cool(TableObject):
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        sara = ColumnInteger()
        amy = ColumnText()

        def __init__(self, sara=None, amy=None):
            TableObject.__init__(self)
            self.sara = sara
            self.amy = amy

        def __str__(self):
            return str(self.sara) + ' ' + str(self.amy)

    db = DB()

    tbl = db.getTable('boo', ObjClass=cool)
    if not tbl.exists:
        tbl.create()

    for i in db.getTables():
        tbl1 = db.getTable(i[2])
        tester.Assert(str(tbl1) == "boo -- [u'amy:TEXT', u'sara:INTEGER']")

    tt = tbl.insert(cool(5, 'wife'))
    tbl.insert(cool(7, 'what'))

    ans = ['5 wife', '7 what']
    for idx, to in enumerate(tbl.get()):
        tester.Assert(str(to) == ans[idx])

    to = tbl.getOne("where amy='wife'")
    tester.Assert(str(to) == '5 wife')
    tester.Assert(str(tt) == '5 wife')

    to.sara = 13
    to.update()

    ans = ['13 wife', '7 what']
    for idx, to in enumerate(tbl.get()):
        tester.Assert(str(to) == ans[idx])

    db.close()
    return 0
Exemplo n.º 3
0
    def work(arg):
        while 1:
            delay = random.randint(0, 5)
            msg = arg.lmwt.getMsg()
            tester.Assert(msg not in arg.seen)
            arg.seen.add(msg)

            if verbose:
                print(msg, 'delaying: ', delay)

            arg.count += 1
            time.sleep(delay)
Exemplo n.º 4
0
def __test__(verbose=False):
    #-------------------------------------------------------------------------------
    """
    used for automated module testing. see L{tester}
    """
    import pylib.tester as tester

    fileName = oss.tmpfile()
    with open(fileName, 'w') as otf:
        otf.write('sara aidan boo connor')

    ts0 = set([1, 3, 5, 6, 7, 10])
    saveDB(fileName, ts0)
    ts1 = loadDB(fileName)
    tester.Assert(ts0 == ts1)

    with open(fileName, 'w') as otf:
        otf.write('sara aidan boo connor stuff')
    ts1 = loadDB(fileName)
    tester.Assert(set() == ts1)

    return 0
Exemplo n.º 5
0
def __test__(verbose=False):
    #-------------------------------------------------------------------------------
    """
    used for automated module testing. see L{tester}
    """
    import pylib.tester as tester
    import random

    for i in range(100):
        n = random.randint(0, 9999999999999999999999999999999999999999999)
        s = cvtNum2QChars(n)
        a = cvtQChars2Num(s)
        print(s, a)
        tester.Assert(n == a)

    for i in range(100):
        n = random.randint(0, 9999999)
        s = cvtNum2QChars(n)
        a = cvtQChars2Num(s)
        print(s, a)
        tester.Assert(n == a)

    return 0
Exemplo n.º 6
0
def __test__():
    #-------------------------------------------------------------------------------
    """
    used for automated module testing. see L{tester}
    """
    import pylib.tester as tester
    tester.Assert(CalcHexDistance(3, 3, 4, 1), 3)
    tester.Assert(CalcHexDistance(2, 4, 4, 1), 4)
    tester.Assert(CalcHexDistance(1, 4, 4, 1), 5)
    tester.Assert(CalcHexDistance(0, 5, 4, 1), 6)

    tester.Assert(CalcHexDistance(3, 3, 5, 0), 4)
    tester.Assert(CalcHexDistance(2, 4, 5, 0), 5)
    tester.Assert(CalcHexDistance(1, 4, 5, 0), 6)
    tester.Assert(CalcHexDistance(0, 5, 5, 0), 7)

    return 0
Exemplo n.º 7
0
def __test__(verbose=False):
    #-------------------------------------------------------------------------------
    """
    used for automated module testing. see L{tester}
    """
    import time
    import random

    import pylib.tester as tester

    class TestObj(object):
        def __init__(self):
            self.lmwt = None
            self.count = 0
            self.seen = set()

    def work(arg):
        while 1:
            delay = random.randint(0, 5)
            msg = arg.lmwt.getMsg()
            tester.Assert(msg not in arg.seen)
            arg.seen.add(msg)

            if verbose:
                print(msg, 'delaying: ', delay)

            arg.count += 1
            time.sleep(delay)

    arg = TestObj()
    lmwt = LastMessageWorkerThread(work, 'work', (arg, ))
    arg.lmwt = lmwt

    lmwt.start()

    for i in range(100):
        lmwt.setMsg(i)
        time.sleep(0.5)

    time.sleep(10)

    if verbose:
        print('Count:', arg.count)

    tester.Assert(arg.count > 8)
    return 0
Exemplo n.º 8
0
def __test__():
    #-------------------------------------------------------------------------------
    import pylib.tester as tester

    v2 = vector(1.3, 2, 3.1)
    tester.Assert(v2.crossProduct(v2) == vector.ZERO)
    tester.Assert(v2 + v2 != 2.1 * v2)
    tester.Assert(v2 + v2 == 2 * v2)
    tester.Assert(v2 - v2 == vector.ZERO)
    tester.Assert(
        vector([1, 0, 0]) *
        vector(point((0, 1, 0))) == vector(vector(0, 0, 1)))
    tester.Assert(vector([v for v in vector.ONE]) == vector.ONE)
Exemplo n.º 9
0
def __test__(verbose=False):
    #-------------------------------------------------------------------------------
    """
    used for automated module testing. see L{tester}
    """
    import pylib.tester as tester
    fw = FileWalker(['sara', 'boo', 'aidan', 'connor'], 'orig')

    results = []
    for idx, i in enumerate(fw):
        if idx == 2:
            fw.add(['amy', 'chris'], 'new')
        results.append(i)

    answer = [(u'orig', 1, u'sara'), (u'orig', 2, u'boo'),
              (u'orig', 3, u'aidan'), (u'new', 1, u'amy'),
              (u'new', 2, u'chris'), (u'orig', 4, u'connor')]

    tester.Assert(results == answer)

    return 0
Exemplo n.º 10
0
def __test__(verbose=None):
    #-------------------------------------------------------------------------------
    """
    used for automated module testing. see L{tester}
    """
    import pylib.tester as tester

    tp = SingleThreadPool(3)
    tester.Assert(__test(tp, 0, verbose))
    tester.Assert(__test(tp, 1, verbose))

    tp = ThreadPool(3)
    tester.Assert(__test(tp, 0, verbose))
    tester.Assert(__test(tp, 1, verbose))

    tp = ProcessPool(3)
    tester.Assert(__test(tp, 0, verbose))
    tester.Assert(__test(tp, 1, verbose))

    return 1
Exemplo n.º 11
0
def __test__(verbose=False):
#-------------------------------------------------------------------------------
    """
    used for automated module testing. see L{tester}
    """
    import pylib.tester as tester

    class TException(Exception): pass

    def usage(rc, s=''):
        raise TException(s)

    t = ['-caa', '--sara', 'cool', 'filename', '--cool', '-5', '-a', '-a']

    args, opts = mopt(t, [('c', 'cat')], ['cool', 'sara'], ['a'], [], "cool")
    tester.Assert(opts.get('cool', 0, int) == 0)
    tester.Assert(len(opts.a) == 2)

    args, opts = mopt(t, [('c', 'cat')], ['cool', 'sara'], ['a'], [], 'this is the prgm', nonOpStopOp=False)
    tester.Assert(opts.get('cool', 0, int) == -5)
    tester.Assert(len(opts.a) == 4)

    args, opts = mopt(t, [('c', 'cat'), 'a'], ['cool', 'sara'], 'this is the prgm', nonOpStopOp=False)
    tester.Assert(opts.get('cool', 0, int) == -5)
    tester.AssertRecvException(AttributeError, opts.get, ('b', ))

    tester.AssertRecvException(TException, mopt, (t, [('c', 'cat')], ['cool', 'sara'], usage))

    tester.AssertRecvException(TException, mopt, (['--help'], [('c', 'cat')], ['cool', 'sara'], usage))
    tester.AssertRecvException(TException, mopt, (['-?'], [('c', 'cat')], ['cool', 'sara'], usage))

    args, opts = mopt(t, [('c', 'cat')], ['cool'], 'this is the prgm', nonOpStopOp=False, skipUnknownOps=True)
    tester.Assert(opts.get('cool', 0, int) == -5)
    tester.Assert(args == ['-a', '-a', '--sara', 'cool', 'filename', '-a', '-a'])

    # test opts as first param
    arg, opts = mopt(opts, [], [], ['a'], ['sara'], '', nonOpStopOp=False)
    tester.Assert(opts.validate({'a': [True, True, True, True], 'sara': ['cool'], 'cat': True, '_usageStr_': 'this is the prgm', 'cool': u'-5', '_args_': [u'filename'],
        '_cmdline_': ['-a', '-a', '--sara', 'cool', 'filename', '-a', '-a']}))

    arg, opts = mopt(opts, [], [], ['a'], ['sara'], nonOpStopOp=False)
    tester.Assert(opts.validate({'a': [True, True, True, True], 'sara': ['cool'],
        'cat': True, '_usageStr_': 'this is the prgm', '_args_': ['filename'], 'cool': '-5', '_cmdline_': ['filename']}))

    arg, opts = mopt(opts, [], [], ['a'], ['sara'], '', nonOpStopOp=False)
    tester.Assert(opts.validate({'a': [True, True, True, True], 'sara': ['cool'],
        'cat': True, '_usageStr_': 'this is the prgm', '_args_': ['filename'], 'cool': '-5', '_cmdline_': ['filename']}))

    arg, opts = mopt(opts, [], [], ['a'], ['sara'], nonOpStopOp=False)
    tester.Assert(opts.validate({'a': [True, True, True, True], 'sara': ['cool'],
        'cat': True, '_usageStr_': 'this is the prgm', '_args_': ['filename'], 'cool': '-5', '_cmdline_': ['filename']}))

    arg, opts = mopt(opts, ['c', 'cool'], [])
    tester.Assert(opts.validate({'a': [True, True, True, True], 'c': None, 'sara': ['cool'], 'cat': True,
        '_usageStr_': u'this is the prgm', '_args_': ['filename'],
        'cool': '-5', '_cmdline_': ['filename']}))
    tester.Assert('c' not in opts)
    tester.Assert('cat' in opts)
    tester.Assert(opts['cat'] is True)

    t = ['-cool', '-run', '5', 'stuff']
    args, opts = mopt(t, ['cool'], ['run'], 'this is the prgm', allowMultiChar=True)
    tester.Assert(opts.validate({'_usageStr_': 'this is the prgm', 'run': '5',
        '_args_': ['stuff'], 'cool': True, '_cmdline_': ['-cool', '-run', '5', 'stuff']}))

    t = ['/cool', '/run', '5', 'stuff']
    args, opts = mopt(t, ['cool'], ['run'], 'this is the prgm', allowMultiChar=True, shortOpMarker='/')
    tester.Assert(opts.validate({'_usageStr_': 'this is the prgm', 'run': '5',
        '_args_': ['stuff'], 'cool': True, '_cmdline_': ['/cool', '/run', '5', 'stuff']}))

    t = ['--sara', 'boo']
    args, opts = mopt(t, ['sara'], ['sara'], 'this is the prgm')
    tester.Assert(opts.validate({'_usageStr_': 'this is the prgm', 'sara': 'boo',
        '_args_': [], '_cmdline_': ['--sara', 'boo']}))

    args, opts = mopt(t, ['sara'], ['sara'], usage)
    tester.AssertRecvException(TException, opts.get, ('sara', '', float))

    t = ['--sara']
    args, opts = mopt(t, ['sara'], ['sara'], 'this is the prgm')
    tester.Assert(opts.validate({'_usageStr_': 'this is the prgm', 'sara': True, '_args_': [], '_cmdline_': ['--sara']}))

    args, opts = mopt(['*.py'], ['sara'], ['sara'], 'this is the prgm')
    tester.AssertRecvException(TypeError, mopt, (['--help'], [('c', 'cat')]))

    args, opts = mopt(['*.py'], ['sara'], ['sara'], 'this is the prgm')
    tester.Assert('options.py' in args)

    args, opts = mopt(['"*.py"'], ['sara'], ['sara'], 'this is the prgm')
    tester.Assert('*.py' in args)

    args, opts = mopt(['coo[123].py'], ['sara'], ['sara'], 'this is the prgm')

    args, opts = mopt(['*.py'], ['sara'], ['sara'], 'this is the prgm', expandWildCards=False)
    tester.Assert('*.py' in args)

    args, opts = mopt(['*.py'], ['sara'], ['sara'], 'this is the prgm', expandWildCards=False, nonOpStopOp=False)
    tester.Assert('*.py' in args)

    t = ['-c', '-r', '5', 'stuff']
    args, opts = mopt(t, [('c', 'cool')], [('r','run')], 'this is the prgm')
    tester.Assert(opts.validate({'_usageStr_': 'this is the prgm', 'run': '5',
        '_args_': ['stuff'], 'cool': True, '_cmdline_': ['-c', '-r', '5', 'stuff']}))

    t = ['-s']
    args, opts = mopt(t, ['s'], ['s'], 'this is the prgm')
    tester.Assert(opts.validate({'_usageStr_': 'this is the prgm', 's': True, '_args_': [], '_cmdline_': ['-s']}))

    t = ['-s', 'boo']
    args, opts = mopt(t, ['s'], ['s'], 'this is the prgm')
    tester.Assert(opts.validate({'_usageStr_': 'this is the prgm', 's': 'boo', '_args_': [], '_cmdline_': ['-s', 'boo']}))

    t = ['-s']
    args, opts = mopt(t, [], [], ['s'], ['s'], 'this is the prgm')
    tester.Assert(opts.validate({'_usageStr_': 'this is the prgm', 's': [True], '_args_': [], '_cmdline_': ['-s']}))

    t = ['-s', 'boo']
    args, opts = mopt(t, [], [], ['s'], ['s'], 'this is the prgm')
    tester.Assert(opts.validate({'_usageStr_': 'this is the prgm', 's': ['boo'], '_args_': [], '_cmdline_': ['-s', 'boo']}))

    t = ['--sara']
    args, opts = mopt(t, [], [], ['sara'], ['sara'], 'this is the prgm')
    tester.Assert(opts.validate({'_usageStr_': 'this is the prgm', 'sara': [True], '_args_': [], '_cmdline_': ['--sara']}))

    t = ['--sara', 'boo']
    args, opts = mopt(t, [], [], ['sara'], ['sara'], 'this is the prgm')
    tester.Assert(opts.validate({'_usageStr_': 'this is the prgm', 'sara': ['boo'], '_args_': [], '_cmdline_': ['--sara', 'boo']}))

    t = ['--sara', 'boo', '--', '--cool']
    args, opts = mopt(t, [], [], ['sara'], ['sara'])
    tester.Assert(opts.validate({'_usageStr_': '', 'sara': ['boo'], '_args_': ['--cool'],
        '_cmdline_': ['--sara', 'boo', '--', '--cool']}))

    t = ['--sara', 'boo', '--', '--cool']
    args, opts = mopt(t, [], [], ['sara'], ['sara'], expandWildCards=False)
    tester.Assert(opts.validate({'_usageStr_': '', 'sara': ['boo'], '_args_': ['--cool'],
        '_cmdline_': ['--sara', 'boo', '--', '--cool']}))

    t = ['--sara', '--', '--cool']
    args, opts = mopt(t, [], [], ['sara'], [], expandWildCards=False)
    tester.Assert(opts.validate({'_usageStr_': '', 'sara': [True], '_args_': ['--cool'],
        '_cmdline_': ['--sara', '--', '--cool']}))

    t = ['--sara']
    tester.AssertRecvException(TException, mopt, (t, [], [('s', 'sara')], usage))
    t = ['-s']
    tester.AssertRecvException(TException, mopt, (t, [], [('s', 'sara')], usage))
    t = ['--sara']
    tester.AssertRecvException(TException, mopt, (t, [], [], [], [('s', 'sara')], usage))
    t = ['-s']
    tester.AssertRecvException(TException, mopt, (t, [], [], [], [('s', 'sara')], usage))

    tester.AssertRecvException(TypeError, mopt, (t, [], [], [('s', 'sara')], usage))

    t = ['---sara', '---', '---cool']
    args, opts = mopt(t, [], [], ['sara'], [], expandWildCards=False, longOpMarker='---')
    tester.Assert(opts.validate({'_usageStr_': '', 'sara': [True], '_args_': ['---cool'],
        '_cmdline_': ['---sara', '---', '---cool']}))

    t = ['---sara', '-s', '-d']
    args, opts = mopt(t, [], [], ['sara'], [], expandWildCards=False, longOpMarker='---', shortOpMarker='---')
    tester.Assert(opts.validate({'_usageStr_': '', 'sara': [True], '_args_': ['-s', '-d'],
        '_cmdline_': ['---sara', '-s', '-d']}))

    return 0
Exemplo n.º 12
0
    <ul>
        <li><a html="date_cool.html">cool</a></li>
        <li><a html="date_aidan.html">cool</a></li>
        <li><a html="date_cool.html">aidan</a></li>
        <li><a html="date_aidan.html">aidan</a></li>
    </ul>
    """

    ###    print "'%s'" % val
    ###    print "'%s'" % good
    ###
    ###    for idx, ch in enumerate(val):
    ###        if good[idx] != ch:
    ###            print "error", idx, "'%s'" % ch, "'%s'" % good[idx]

    tester.Assert(val == good, "Substitution Comparison Failed")

    tmp = Template('cvs.exe ci\n$$$ if msg:\n-m "$msg"\n$$$ end\n$file')
    tmp.dbg = 0

    try:
        val1 = tmp.sub({'msg': '', 'file': 'cool'}, ' ')
        val2 = tmp.sub({'msg': 'cool', 'file': 'ff'}, ' ')
    except TemplateException:
        print tmp.printErrors()
        raise

    tester.Assert(val1 == 'cvs.exe ci cool',
                  "Substitution Comparison Failed 1")
    tester.Assert(val2 == 'cvs.exe ci -m "cool" ff',
                  "Substitution Comparison Failed 2")
Exemplo n.º 13
0
Arquivo: relib.py Projeto: chyser/bin
def __test__():
    #-------------------------------------------------------------------------------
    tester.Assert(eq("bob", "[_a-zA-Z][_a-zA-Z0-9]+"))
    tester.Assert(not eq("bob ", "[_a-zA-Z][_a-zA-Z0-9]+"))
    tester.Assert(not eq(" bob ", "[_a-zA-Z][_a-zA-Z0-9]+"))
    tester.Assert(not eq("bib ", "[_a-zA-Z][_a-zA-Z0-9]+"))

    s = " cool $$% dogf$!d$!"

    sf = scanf(s)
    tester.Assert(not sf.scan("cool 100% dogfood") == ('100', ))
    tester.Assert(sf.scan(" cool 100% dogfodfdfdod ") == ('100', ))
    tester.Assert(sf.scan(" cool a% dogfodfdfod ") == ('a', ))
    tester.Assert(
        sf.scan(
            "             cool    1234 6%      dogfooddddddddddddddddddddddddddddd"
        ) == ('1234 6', ))

    s = "warning: line $$, column $$"
    sf = scanf(s)
    tester.Assert(sf.scan("warning: line 31, column 42") == ('31', '42'))

    rex = CvtFileWildCardToRE('*.py;data?.dat')
    ee = reCmp(rex)

    rex = CvtFileWildCardToRE('*.py')
    tester.Assert(ee.eq('C:/bad/cool.py'))
    tester.Assert(ee.eq('C:\\bad\\cool.py'))
    tester.Assert(not ee.eq('da3ta5.dat'))
    tester.Assert(ee.eq('data5.dat'))
    tester.Assert(eq('C:/bad/cool.py', rex))
    tester.Assert(eq('C:\\bad\\cool.py', rex))

    tester.Assert(
        strPartition('==|-=',
                     'this is a "very cool" == test -= """more stuff"""') == [[
                         'this', 'is', 'a', 'very cool'
                     ], ['=='], ['test'], ['-='], ['more stuff']])