def test_readSimpleCsv(tmpdir): d = tmpdir.mkdir('dir') p = d.join('test.txt') with pytest.raises(argparse.ArgumentTypeError): helper.checkFile(str(p)) with helper.openNormalOrGz(str(p),'w') as f: f.write("1,'2',3 \n \n \na,\"bb\",ccc\n 2,3,4 ") assert(helper.readSimpleCsv(str(p))==[['1','2','3'],['a','bb','ccc'],["2","3","4"]]) with helper.openNormalOrGz(str(p),'w') as f: f.write("1,2,3\n\n \na,bb,ccc,d\n 2,3,4 ") with pytest.raises(ValueError): helper.readSimpleCsv(str(p))
def test_readSimpleCsv(tmpdir): d = tmpdir.mkdir('dir') p = d.join('test.txt') with pytest.raises(argparse.ArgumentTypeError): helper.checkFile(str(p)) with helper.openNormalOrGz(str(p), 'w') as f: f.write("1,'2',3 \n \n \na,\"bb\",ccc\n 2,3,4 ") assert (helper.readSimpleCsv(str(p)) == [['1', '2', '3'], ['a', 'bb', 'ccc'], ["2", "3", "4"]]) with helper.openNormalOrGz(str(p), 'w') as f: f.write("1,2,3\n\n \na,bb,ccc,d\n 2,3,4 ") with pytest.raises(ValueError): helper.readSimpleCsv(str(p))
def test_checkFile(tmpdir): d = tmpdir.mkdir('dir') p = d.join('test.txt') with pytest.raises(argparse.ArgumentTypeError): helper.checkFile(str(d)) #doesn't exist yet with pytest.raises(argparse.ArgumentTypeError): helper.checkFile(str(p)) p.write("test") assert helper.checkFile(str(p))==str(p) #make unreadable os.chmod(str(p),os.stat(str(p)).st_mode & ~stat.S_IREAD) with pytest.raises(argparse.ArgumentTypeError): helper.checkFile(str(p))
def test_checkFile(tmpdir): d = tmpdir.mkdir('dir') p = d.join('test.txt') with pytest.raises(argparse.ArgumentTypeError): helper.checkFile(str(d)) #doesn't exist yet with pytest.raises(argparse.ArgumentTypeError): helper.checkFile(str(p)) p.write("test") assert helper.checkFile(str(p)) == str(p) #make unreadable os.chmod(str(p), os.stat(str(p)).st_mode & ~stat.S_IREAD) with pytest.raises(argparse.ArgumentTypeError): helper.checkFile(str(p)) #check pipe p = d.join('test.pipe') with pytest.raises(argparse.ArgumentTypeError): helper.checkFile(str(d)) os.mkfifo(str(p)) with pytest.raises(argparse.ArgumentTypeError): helper.checkFile(str(p), False) assert (helper.checkFile(str(p), True)) == str(p) assert (helper.checkFile(str(p))) == str(p)