def path_tests(): assert vfpfunc.home() == os.getcwd() S.handle = open('test_lib_file', 'w') S.handle.close() assert not vfpfunc.isblank(vfpfunc.locfile('test_lib_file')) os.chdir('..') assert vfpfunc.home() != os.getcwd() assert not vfpfunc.isblank(vfpfunc.locfile('test_lib_file')) os.remove(os.path.join(vfpfunc.home(), 'test_lib_file'))
def path_tests(): vfpvar.pushscope() assert vfpfunc.home() == os.getcwd() vfpvar['handle'] = open('test_lib_file', 'w') vfpvar['handle'].close() assert not vfpfunc.isblank(vfpfunc.locfile('test_lib_file')) os.chdir('..') assert vfpfunc.home() != os.getcwd() assert not vfpfunc.isblank(vfpfunc.locfile('test_lib_file')) os.remove(os.path.join(vfpfunc.home(), 'test_lib_file')) vfpvar.popscope()
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
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()