How to use read_from_file method in autotest

Best Python code snippet using autotest_python

test_all.py

Source:test_all.py Github

copy

Full Screen

...49def create_directory(dirname, path):50 os.makedirs(os.path.join(dirname, *path))51 # Needed to let pcachefs propagate changes52 time.sleep(.1)53def read_from_file(dirname, path):54 try:55 with open(os.path.join(dirname, *path), 'r') as f:56 return f.read()57 except IOError as e:58 print('Could not open', os.path.join(dirname, *path), e)59 return None60def remove_file(dirname, path):61 os.remove(os.path.join(dirname, *path))62class ListDir(object):63 def __init__(self, files, dirs):64 self.files = sorted(list(files))65 self.dirs = sorted(list(dirs))66 def __repr__(self):67 return '<ListDir files: {}, dirs: {}>'.format(self.files, self.dirs)68 def __eq__(self, other):69 return self.dirs == other.dirs and self.files == other.files70 def __contains__(self, what):71 return what in self.files or what in self.dirs72def list_dir(dirname, path=None):73 files = set()74 dirs = set()75 root = os.path.join(dirname, *(path or []))76 for object in os.listdir(root):77 is_dir = stat.S_ISDIR(os.stat(os.path.join(root, object)).st_mode)78 if is_dir:79 dirs.add(object)80 else:81 files.add(object)82 return ListDir(files, dirs)83def test_create_file(pcachefs, sourcedir, mountdir):84 assert 'a' not in list_dir(sourcedir)85 assert 'a' not in list_dir(mountdir)86 assert read_from_file(sourcedir, ['a']) is None87 assert read_from_file(mountdir, ['a']) is None88 write_to_file(sourcedir, ['a'], '1')89 assert 'a' in list_dir(sourcedir)90 assert 'a' in list_dir(mountdir)91 assert read_from_file(sourcedir, ['a']) == '1'92 assert read_from_file(mountdir, ['a']) == '1'93def test_cached_file_not_updated(pcachefs, sourcedir, mountdir):94 write_to_file(sourcedir, ['a'], '1')95 # load in cache96 read_from_file(mountdir, ['a'])97 write_to_file(sourcedir, ['a'], '2')98 assert 'a' in list_dir(sourcedir)99 assert 'a' in list_dir(mountdir)100 assert read_from_file(sourcedir, ['a']) == '2'101 assert read_from_file(mountdir, ['a']) == '1'102def test_only_cached_file_at_read(pcachefs, sourcedir, mountdir):103 write_to_file(sourcedir, ['a'], '1')104 write_to_file(sourcedir, ['a'], '2')105 assert 'a' in list_dir(sourcedir)106 assert 'a' in list_dir(mountdir)107 assert read_from_file(sourcedir, ['a']) == '2'108 assert read_from_file(mountdir, ['a']) == '2'109def test_create_directory(pcachefs, sourcedir, mountdir):110 assert 'a' not in list_dir(sourcedir)111 assert 'a' not in list_dir(mountdir)112 assert read_from_file(sourcedir, ['a']) is None113 assert read_from_file(mountdir, ['a']) is None114 create_directory(sourcedir, ['a'])115 assert 'a' in list_dir(sourcedir)116 assert 'a' in list_dir(mountdir)117 write_to_file(sourcedir, ['a', 'a'], '1')118 assert 'a' in list_dir(sourcedir)119 assert 'a' in list_dir(mountdir)120 assert read_from_file(sourcedir, ['a', 'a']) == '1'121 assert read_from_file(mountdir, ['a', 'a']) == '1'122def test_cached_directory_not_updated(pcachefs, sourcedir, mountdir):123 assert 'a' not in list_dir(sourcedir)124 assert 'a' not in list_dir(mountdir)125 assert read_from_file(sourcedir, ['a']) is None126 assert read_from_file(mountdir, ['a']) is None127 create_directory(sourcedir, ['a'])128 assert 'a' in list_dir(sourcedir)129 assert 'a' in list_dir(mountdir)130 write_to_file(sourcedir, ['a', 'a'], '1')131 assert 'a' in list_dir(sourcedir, ['a'])132 assert 'a' in list_dir(mountdir, ['a'])133 assert read_from_file(sourcedir, ['a', 'a']) == '1'134 assert read_from_file(mountdir, ['a', 'a']) == '1'135 # FIXME: not consistent behavior, b does not appear in listdir136 # although we can read the file.137 write_to_file(sourcedir, ['a', 'a'], '2')138 write_to_file(sourcedir, ['a', 'b'], '3')139 assert 'a' in list_dir(sourcedir, ['a'])140 assert 'a' in list_dir(mountdir, ['a'])141 assert 'b' in list_dir(sourcedir, ['a'])142 assert 'b' not in list_dir(mountdir, ['a'])143 assert read_from_file(sourcedir, ['a', 'a']) == '2'144 assert read_from_file(mountdir, ['a', 'a']) == '1'145 assert read_from_file(sourcedir, ['a', 'b']) == '3'146 assert read_from_file(mountdir, ['a', 'b']) == '3'147def test_read_cache(pcachefs, sourcedir, mountdir):148 write_to_file(sourcedir, ['a'], '1')149 assert list_dir(mountdir) == ListDir(['a'], ['.pcachefs'])150 assert list_dir(mountdir, ['.pcachefs']) == ListDir([], ['a'])151 assert list_dir(mountdir, ['.pcachefs', 'a']) == ListDir(['cached'], [])152 assert read_from_file(mountdir, ['.pcachefs', 'a', 'cached']) == '0'153 read_from_file(mountdir, ['a'])154 assert read_from_file(mountdir, ['.pcachefs', 'a', 'cached']) == '1'155def test_reload_cache(pcachefs, sourcedir, mountdir):156 write_to_file(sourcedir, ['a'], '1')157 # load in cache158 read_from_file(mountdir, ['a'])159 write_to_file(sourcedir, ['a'], '2')160 assert read_from_file(mountdir, ['a']) == '1'161 assert list_dir(mountdir) == ListDir(['a'], ['.pcachefs'])162 assert read_from_file(mountdir, ['.pcachefs', 'a', 'cached']) == '1'163 write_to_file(mountdir, ['.pcachefs', 'a', 'cached'], '1')164 # remove source file165 remove_file(sourcedir, ['a'])166 assert read_from_file(mountdir, ['.pcachefs', 'a', 'cached']) == '1'167 assert read_from_file(mountdir, ['a']) == '2'168def test_remove_cache(pcachefs, sourcedir, mountdir, cachedir):169 assert read_from_file(cachedir, 'cache.data') is None170 write_to_file(sourcedir, ['a'], '1')171 assert read_from_file(mountdir, ['a']) == '1'172 assert read_from_file(cachedir, ['a', 'cache.data']) == '1'173 write_to_file(mountdir, ['.pcachefs', 'a', 'cached'], '0')174 assert read_from_file(cachedir, ['a', 'cache.data']) is None175 assert read_from_file(mountdir, ['a']) == '1'...

Full Screen

Full Screen

day3.py

Source:day3.py Github

copy

Full Screen

1import sys2def read_file(filename):3 try:4 with open(filename) as f:5 content = f.readlines()6 # I converted the file data to integers because I know7 # that the input data is made up of numbers greater than 08 content = [info.strip() for info in content]9 except:10 print('Error to read file')11 sys.exit()12 return content13if __name__ == "__main__":14 read_from_file_basic = read_file("day3input.txt")15 # read_from_file = ["""16 # ..##.......17 # #...#...#..18 # .#....#..#.19 # ..#.#...#.#20 # .#...##..#.21 # ..#.##.....22 # .#.#.#....#23 # .#........#24 # #.##...#...25 # #...##....#26 # .#..#...#.#27 # """]28 read_from_file = [row * 35 for row in read_from_file_basic]29 print("-----------------------------PART1-----------------------------------")30 read_from_file = [row * 35 for row in read_from_file_basic]31 pos = 032 for index, row in enumerate(read_from_file):33 if index == 0:34 continue35 pos += 336 if row[pos] == "#":37 read_from_file[index] = row[:pos] + "X" + row[pos + 1:]38 if row[pos] == ".":39 read_from_file[index] = row[:pos] + "O" + row[pos + 1:]40 for row in read_from_file:41 print(row * 1)42 print(sum([row.count("X") for row in read_from_file]))43 print("-----------------------------PART2-----------------------------------")44 print("Right 1, down 1.")45 read_from_file = [row * 35 for row in read_from_file_basic]46 pos = 047 for index, row in enumerate(read_from_file):48 if index == 0:49 continue50 pos += 151 if row[pos] == "#":52 read_from_file[index] = row[:pos] + "X" + row[pos + 1:]53 if row[pos] == ".":54 read_from_file[index] = row[:pos] + "O" + row[pos + 1:]55 num1 = sum([row.count("X") for row in read_from_file])56 print(num1)57 print("Right 3, down 1.")58 read_from_file = [row * 35 for row in read_from_file_basic]59 pos = 060 for index, row in enumerate(read_from_file):61 if index == 0:62 continue63 pos += 364 if row[pos] == "#":65 read_from_file[index] = row[:pos] + "X" + row[pos + 1:]66 if row[pos] == ".":67 read_from_file[index] = row[:pos] + "O" + row[pos + 1:]68 num2 = sum([row.count("X") for row in read_from_file])69 print(num2)70 print("Right 5, down 1.")71 read_from_file = [row * 500 for row in read_from_file_basic]72 pos = 073 for index, row in enumerate(read_from_file):74 if index == 0:75 continue76 pos += 577 if row[pos] == "#":78 read_from_file[index] = row[:pos] + "X" + row[pos + 1:]79 if row[pos] == ".":80 read_from_file[index] = row[:pos] + "O" + row[pos + 1:]81 num3 = sum([row.count("X") for row in read_from_file])82 print(num3)83 print("Right 7, down 1.")84 read_from_file = [row * 500 for row in read_from_file_basic]85 pos = 086 for index, row in enumerate(read_from_file):87 if index == 0:88 continue89 pos += 790 if row[pos] == "#":91 read_from_file[index] = row[:pos] + "X" + row[pos + 1:]92 if row[pos] == ".":93 read_from_file[index] = row[:pos] + "O" + row[pos + 1:]94 num4 = sum([row.count("X") for row in read_from_file])95 print(num4)96 print("Right 1, down 2.")97 read_from_file = [row * 35 for row in read_from_file_basic]98 pos = 099 for index in range(0, len(read_from_file), 2):100 if index == 0:101 continue102 pos += 1103 if read_from_file[index][pos] == "#":104 read_from_file[index] = read_from_file[index][:pos] + "X" + read_from_file[index][pos + 1:]105 if read_from_file[index][pos] == ".":106 read_from_file[index] = read_from_file[index][:pos] + "O" + read_from_file[index][pos + 1:]107 num5 = sum([row.count("X") for row in read_from_file])108 print(num5)...

Full Screen

Full Screen

Numerology_Application.py

Source:Numerology_Application.py Github

copy

Full Screen

1from tkinter import*2from tkinter.messagebox import*3from module1 import*4letters=read_from_file("letters.txt")5numbers=read_from_file("numbers.txt")6one=read_from_file("one.txt")7two=read_from_file("two.txt")8three=read_from_file("three.txt")9four=read_from_file("four.txt")10five=read_from_file("five.txt")11six=read_from_file("six.txt")12seven=read_from_file("seven.txt")13eight=read_from_file("eight.txt")14nine=read_from_file("nine.txt")15window=Tk()16window.title("Число имени!")17window.geometry("1500x900")18lbl=Label(window, text="Узнаем число твоего имени!\nВведи имя:", font="Arial 20", fg="blue" )19ent=Entry(window, font="Arial 30", fg="blue", bg="grey")20btn=Button(window, text="Нажми меня, как введёшь имя", font="Arial 18", fg="blue", command=lambda:name_number(letters,numbers,ent.get().lower(),lbl3))21lbl2=Label(window, text="Число твоего имени: ", font="Coral 14", fg="blue",)22lbl3=Label(window, font="Coral 10", bg="#FDD9B5", fg="black")23lbl.pack()24ent.pack()25btn.pack()26lbl2.pack(side=LEFT)27lbl3.pack(side=RIGHT)28window.mainloop()

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 autotest 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