How to use test_readfile method in avocado

Best Python code snippet using avocado_python

test_FileIO.py

Source:test_FileIO.py Github

copy

Full Screen

...4class TestPepXML(unittest.TestCase):5 def setUp(self):6 dirname = os.path.dirname(os.path.abspath(__file__))7 self.filename = os.path.join(dirname, "test.pep.xml").encode()8 def test_readfile(self):9 pepxml_file = pyopenms.PepXMLFile()10 peps = []11 prots = []12 pepxml_file.load(self.filename, prots, peps)13 def test_readfile_content(self):14 pepxml_file = pyopenms.PepXMLFile()15 peps = []16 prots = []17 pepxml_file.load(self.filename, prots, peps)18 self.assertEqual( len(prots), 1)19 self.assertEqual( len(peps), 3)20 self.assertEqual( peps[0].getHits()[0].getSequence().toString(), b"LAPSAAEDGAFR")21class TestIdXML(unittest.TestCase):22 def setUp(self):23 dirname = os.path.dirname(os.path.abspath(__file__))24 self.filename = os.path.join(dirname, "test.idXML").encode()25 def test_readfile(self):26 idxml_file = pyopenms.IdXMLFile()27 peps = []28 prots = []29 idxml_file.load(self.filename, prots, peps)30 def test_readfile_content(self):31 idxml_file = pyopenms.IdXMLFile()32 peps = []33 prots = []34 idxml_file.load(self.filename, prots, peps)35 self.assertEqual( len(prots), 1)36 self.assertEqual( len(peps), 3)37class TestIndexedMzMLFileLoader(unittest.TestCase):38 def setUp(self):39 dirname = os.path.dirname(os.path.abspath(__file__))40 self.filename = os.path.join(dirname, "test.indexed.mzML").encode()41 def test_readfile(self):42 e = pyopenms.OnDiscMSExperiment();43 success = pyopenms.IndexedMzMLFileLoader().load(self.filename, e)44 self.assertTrue(success)45 def test_readfile_content(self):46 e = pyopenms.OnDiscMSExperiment();47 pyopenms.IndexedMzMLFileLoader().load(self.filename, e)48 self.assertEqual( e.getNrSpectra() , 2)49 self.assertEqual( e.getNrChromatograms() , 1)50 s = e.getSpectrum(0)51 data_mz, data_int = s.get_peaks()52 self.assertEqual( len(data_mz), 19914)53 self.assertEqual( len(data_int), 19914)54 self.assertEqual( len(e.getSpectrum(1).get_peaks()[0]), 19800)55 self.assertEqual( len(e.getSpectrum(1).get_peaks()[1]), 19800)56 self.assertEqual( len(e.getChromatogram(0).get_peaks()[0]), 48)57 self.assertEqual( len(e.getChromatogram(0).get_peaks()[1]), 48)58 raised = False59 try:60 e.getChromatogram(2).get_peaks()61 except Exception as e:62 raised = True63 self.assertTrue(raised)64class TestIndexedMzMLFile(unittest.TestCase):65 def setUp(self):66 dirname = os.path.dirname(os.path.abspath(__file__))67 self.filename = os.path.join(dirname, "test.indexed.mzML").encode()68 def test_readfile(self):69 f = pyopenms.IndexedMzMLFile()70 f.openFile(self.filename)71 self.assertTrue(f.getParsingSuccess())72 def test_readfile_content(self):73 f = pyopenms.IndexedMzMLFile()74 f.openFile(self.filename)75 self.assertEqual( f.getNrSpectra() , 2)76 self.assertEqual( f.getNrChromatograms() , 1)77 s = f.getSpectrumById(0)78 mzdata = s.getMZArray()79 intdata = s.getIntensityArray()80 self.assertEqual( len(mzdata), 19914)81 self.assertEqual( len(intdata), 19914)82if __name__ == '__main__':...

Full Screen

Full Screen

class04_files.py

Source:class04_files.py Github

copy

Full Screen

1#### Class 032#### Reading and writing files3## Reading text files ------------------------------------------------4import sys5## Read all lines as one string6with open('test_readfile.txt') as f:7 the_whole_thing = f.read()8 print the_whole_thing9## Read line by line10with open('test_readfile.txt') as f:11 lines_list = f.readlines()12 for l in lines_list:13 print l14## More efficiently we can loop over the file object15## (i.e. we don't need the variable lines)16with open('test_readfile.txt') as f: 17 for l in f:18 print l19 20 21## We can also manually open and close files,22## now we need to handle exceptions and close23## I never do this24f = open('test_readfile.txt')25print f.read()26f.close()27## Writing text files ------------------------------------------------28## Writing files is easy,29## open command takes r, w, a, plus some others30with open('test_writefile.txt', 'w') as f:31 ## wipes the file clean and opens it32 f.write("Hi guys.")33 f.write("Does this go on the second line?")34 f.writelines(['a\n', 'b\n', 'c\n'])35with open('test_writefile.txt', 'a') as f:36 ## appends37 f.write("I got appended!")38## Writing csv files ------------------------------------------------39import csv40## Open a file stream and create a CSV writer object41with open('test_writecsv.txt', 'wb') as f:42 my_writer = csv.writer(f)43 for i in range(1, 100):44 my_writer.writerow([i, i-1])45## Now read in the csv46with open('test_writecsv.txt', 'rb') as f:47 my_reader = csv.reader(f)48 mydat = []49 for row in my_reader:50 mydat.append(row)51print mydat52 53## Adding column names54with open('test_csvfields.txt', 'wb') as f:55 my_writer = csv.DictWriter(f, fieldnames = ("A", "B"))56 my_writer.writeheader()57 for i in range(1, 100):58 my_writer.writerow({"B":i, "A":i-1})59 60 61with open('test_csvfields.csv', 'rb') as f:62 my_reader = csv.DictReader(f)63 for row in my_reader:64 print row65# Copyright (c) 2014 Matt Dickenson66# 67# Permission is hereby granted, free of charge, to any person obtaining a copy68# of this software and associated documentation files (the "Software"), to deal69# in the Software without restriction, including without limitation the rights70# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell71# copies of the Software, and to permit persons to whom the Software is72# furnished to do so, subject to the following conditions:73# 74# The above copyright notice and this permission notice shall be included in all75# copies or substantial portions of the Software.76# 77# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR78# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,79# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE80# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER81# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,82# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE...

Full Screen

Full Screen

tt.py

Source:tt.py Github

copy

Full Screen

1import os2def test_readfile(filepath):3 """4 :param filepath:5 :return:6 """7 with open(filepath, "r") as r:8 return r.readlines()9# def getallfiles(path):10# allfile=[]11# for dirpath, dirnames, filenames in os.walk(path):12# for dir in dirnames:13# allfile.append(os.path.join(dirpath,dir))14# for name in filenames:15# allfile.append(os.path.join(dirpath, name))16# return allfile17#18#19# if __name__ == '__main__':20# path = "D:\qycache"21# allfile = getallfiles(path)22# for file in allfile:23# print(file)24if __name__ == '__main__':25 path = "2020_09_28 桃花族无毛宣言177GB合集2020_09_28 桃花族无毛宣言177GB合集_2.jpg"26 print(test_readfile(path))27 if len(test_readfile(path)) == 0: # 空文件,删除...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful