示例#1
0
def date_tests():
    somedate = False  # LOCAL Declaration
    somedate = dt.date(2017, 6, 30)
    assert somedate == dt.date(2017, 6, 30)
    assert vfpfunc.dow_fix(somedate.weekday()) == 6
    assert somedate.strftime('%A') == 'Friday'
    assert somedate.month == 6
    assert somedate.strftime('%B') == 'June'
    assert somedate.strftime('%d %B %Y') == '30 June 2017'
    assert len(dt.datetime.now().time().strftime('%H:%M:%S')) == 8
    assert len(dt.datetime.now().time().strftime('%H:%M:%S.%f')[:11]) == 11
    assert dt.datetime.combine(somedate,
                               dt.datetime.min.time()) == dt.datetime(
                                   2017, 6, 30, 0)
    assert vfpfunc.gomonth(somedate, -4) == dt.date(2017, 2, 28)
    assert vfpfunc.vartype(somedate) == 'D'
    assert vfpfunc.vartype(
        dt.datetime.combine(somedate, dt.datetime.min.time())) == 'T'
示例#2
0
def date_tests():
    M.add_local('somedate')
    S.somedate = dt.date(2017, 6, 30)
    assert S.somedate == dt.date(2017, 6, 30)
    assert vfpfunc.dow_fix(S.somedate.weekday()) == 6
    assert S.somedate.strftime('%A') == 'Friday'
    assert S.somedate.month == 6
    assert S.somedate.strftime('%B') == 'June'
    assert S.somedate.strftime('%d %B %Y') == '30 June 2017'
    assert len(dt.datetime.now().time().strftime('%H:%M:%S')) == 8
    assert len(dt.datetime.now().time().strftime('%H:%M:%S.%f')[:11]) == 11
    assert dt.datetime.combine(S.somedate,
                               dt.datetime.min.time()) == dt.datetime(
                                   2017, 6, 30, 0)
    assert vfpfunc.gomonth(S.somedate, -4) == dt.date(2017, 2, 28)
    assert vfpfunc.vartype(S.somedate) == 'D'
    assert vfpfunc.vartype(
        dt.datetime.combine(S.somedate, dt.datetime.min.time())) == 'T'
示例#3
0
def math_tests():
    num_value = False  # LOCAL Declaration
    num_value = math.pi
    assert round(math.pi, 2) == 3.14
    assert abs(math.tan(math.radians(45)) - 1) < 0.001
    assert abs(math.sin(math.radians(90)) - 1) < 0.001
    assert abs(math.cos(math.radians(90)) - 0) < 0.001
    assert abs(math.cos(math.radians(45)) - math.sqrt(2) / 2) < 0.001
    assert 0 < random.random() and random.random() < 1

    stringval = False  # LOCAL Declaration
    stringval = '1e5'
    assert float(stringval) == 100000
    assert vfpfunc.vartype(num_value) == 'N'
示例#4
0
def math_tests():
    M.add_local('num_value')
    S.num_value = math.pi
    assert round(math.pi, 2) == 3.14
    assert abs(math.tan(math.radians(45)) - 1) < 0.001
    assert abs(math.sin(math.radians(90)) - 1) < 0.001
    assert abs(math.cos(math.radians(90)) - 0) < 0.001
    assert abs(math.cos(math.radians(45)) - math.sqrt(2) / 2) < 0.001
    assert 0 < random.random() and random.random() < 1

    M.add_local('stringval')
    S.stringval = '1e5'
    assert float(S.stringval) == 100000
    assert vfpfunc.vartype(S.num_value) == 'N'
示例#5
0
文件: test_lib.py 项目: vfp9/vfp2py
def string_tests():
    S.cstring = 'AAA  aaa, BBB bbb, CCC ccc.'
    assert vfpfunc.vartype(S.cstring) == 'C'
    assert len([w for w in S.cstring.split() if w]) == 6
    assert len([w for w in S.cstring.split(',') if w]) == 3
    assert len([w for w in S.cstring.split('.') if w]) == 1
    assert vfpfunc.getwordnum(S.cstring, 2) == 'aaa,'
    assert vfpfunc.getwordnum(S.cstring, 2, ',') == ' BBB bbb'
    assert vfpfunc.getwordnum(S.cstring, 2, '.') == ''
    assert vfpfunc.like('Ab*t.???', 'About.txt')
    assert not vfpfunc.like('Ab*t.???', 'about.txt')
    assert not ''[:1].isalpha()
    assert 'a123'[:1].isalpha()
    assert not '1abc'[:1].isalpha()
    assert not ''[:1].islower()
    assert 'test'[:1].islower()
    assert not 'Test'[:1].islower()
    assert not ''[:1].isdigit()
    assert '1abc'[:1].isdigit()
    assert not 'a123'[:1].isdigit()
    assert not ''[:1].isupper()
    assert 'Test'[:1].isupper()
    assert not 'test'[:1].isupper()
    assert vfpfunc.isblank('')
    assert not vfpfunc.isblank('test')
    assert vfpfunc.isblank(None)
    S.cstring = ' AAA   '
    assert S.cstring.strip() == 'AAA'
    assert S.cstring.rstrip() == ' AAA'
    assert S.cstring.lstrip() == 'AAA   '
    assert S.cstring.rstrip() == S.cstring.rstrip()
    assert vfpfunc.strextract('This {{is}} a {{template}}', '{{', '}}') == 'is'
    assert vfpfunc.strextract('This {{is}} a {{template}}', '{{', '}}',
                              2) == 'template'
    assert vfpfunc.strextract('This {{is}} a {{template}}',
                              '{{is}}') == ' a {{template}}'
    assert vfpfunc.strextract('This {{is}} a {{template}}', '{{IS}}', '', 1,
                              1) == ' a {{template}}'
    assert '123AAbbB'.lower().find('aab'.lower()) + 1 == 4
    S.cstring = vfpfunc.text(
        ['      123AAbbbB', '      TESTTEST', '      TEXTLINES', '   '],
        show=False)
    assert S.cstring == '123AAbbbBTESTTESTTEXTLINES'
    S.cstring = '123AAbbbB\r\nTESTTEST\r\nTEXTLINES'
    assert vfpfunc.atline('T', S.cstring) == 2
    assert vfpfunc.ratline('T', S.cstring) == 3
示例#6
0
def string_tests():
    vfpvar.pushscope()
    vfpvar['cstring'] = 'AAA  aaa, BBB bbb, CCC ccc.'
    assert vfpfunc.vartype(vfpvar['cstring']) == 'C'
    assert len([w for w in vfpvar['cstring'].split() if w]) == 6
    assert len([w for w in vfpvar['cstring'].split(',') if w]) == 3
    assert len([w for w in vfpvar['cstring'].split('.') if w]) == 1
    assert vfpfunc.getwordnum(vfpvar['cstring'], 2) == 'aaa,'
    assert vfpfunc.getwordnum(vfpvar['cstring'], 2, ',') == ' BBB bbb'
    assert vfpfunc.getwordnum(vfpvar['cstring'], 2, '.') == ''
    assert vfpfunc.like('Ab*t.???', 'About.txt')
    assert not vfpfunc.like('Ab*t.???', 'about.txt')
    assert not ''[:1].isalpha()
    assert 'a123'[:1].isalpha()
    assert not '1abc'[:1].isalpha()
    assert not ''[:1].islower()
    assert 'test'[:1].islower()
    assert not 'Test'[:1].islower()
    assert not ''[:1].isdigit()
    assert '1abc'[:1].isdigit()
    assert not 'a123'[:1].isdigit()
    assert not ''[:1].isupper()
    assert 'Test'[:1].isupper()
    assert not 'test'[:1].isupper()
    assert vfpfunc.isblank('')
    assert not vfpfunc.isblank('test')
    assert vfpfunc.isblank(None)
    vfpvar['cstring'] = ' AAA   '
    assert vfpvar['cstring'].strip() == 'AAA'
    assert vfpvar['cstring'].rstrip() == ' AAA'
    assert vfpvar['cstring'].lstrip() == 'AAA   '
    assert vfpvar['cstring'].lstrip() == vfpvar['cstring'].lstrip()
    assert vfpfunc.strextract('This {{is}} a {{template}}', '{{', '}}') == 'is'
    assert vfpfunc.strextract('This {{is}} a {{template}}', '{{', '}}',
                              2) == 'template'
    assert vfpfunc.strextract('This {{is}} a {{template}}',
                              '{{is}}') == ' a {{template}}'
    assert vfpfunc.strextract('This {{is}} a {{template}}', '{{IS}}', '', 1,
                              1) == ' a {{template}}'
    assert '123AAbbB'.lower().find('aab'.lower()) + 1 == 4
    vfpvar['cstring'] = vfpfunc.text(
        [u'      123AAbbbB', u'      TESTTEST', u'      TEXTLINES', u'   '],
        show=False)
    assert vfpvar['cstring'] == '123AAbbbBTESTTESTTEXTLINES'
    vfpvar.popscope()