Best Python code snippet using autotest_python
job_serializer_unittest.py
Source:job_serializer_unittest.py
...189 try:190 temp_binary.write(self.pb_job.SerializeToString())191 temp_binary.flush()192 js = job_serializer.JobSerializer()193 self.from_pb_job = js.deserialize_from_binary(temp_binary.name)194 finally:195 temp_binary.close()196 def test_keyval_dict(self):197 """Check if the contents of the dictionary are the same. """198 self.assertEqual(len(self.tko_job.keyval_dict),199 len(self.from_pb_job.keyval_dict))200 self.check_dict(self.tko_job.keyval_dict,201 self.from_pb_job.keyval_dict)202 def test_tests(self):203 """Check if all the test are the same.204 """205 for test, newtest in zip(self.tko_job.tests,206 self.from_pb_job.tests):207 self.assertEqual(test.subdir, newtest.subdir)...
gui_main.py
Source:gui_main.py
1import wx2import sys3import deserialize_from_binary as seqconvert4import ntpath5import subprocess6import pkg_resources7from tkinter import *8from tkinter import filedialog9import note_dict10import color_dict11import librosa12##########################13# Credits:14# Slach15# Murtada5816# The Python discord and StackExchange for answers to my obscure questions17# Sorry to all of you for so many questions about tkinter and weird issues, and thanks for your time18##########################1920note_ids = []2122def create_note(note_type, length, ntime, instrument, volume):23 note_color = (color_dict.setcolor(str(instrument)))24 notey = ((' '.join(note_dict.notedict[noteprocess] for noteprocess in str(note_type).split())).split(' '))25 note = int(notey[0])*1226 print(ntime)27 print(note)28 print(length)29 print(volume)30 note_ids.append(canvas.create_rectangle((int(ntime) * 16) + 100, note, (int(ntime)*16) + 100 + (length * 16), note + 12,31 fill=note_color, tags=[note_color, 'note']))323334# Get display resolution for canvas/window sizes35display = wx.App(False)36displaywidth, displayheight = wx.GetDisplaySize()3738# install needed libraries39required = {'wxpython', 'protobuf', 'turtle', 'tk', 'playsound'}40installed = {pkg.key for pkg in pkg_resources.working_set}41missing = required - installed42if missing:43 python = sys.executable44 subprocess.check_call([python, '-m', 'pip', 'install', *missing], stdout=subprocess.DEVNULL)454647def clearall():48 canvas.delete('note')495051def loadsequence(sequenceloaddir):52 clearall()53 # Thanks to Murtada58 for this part5455 class Note:56 def __init__(self, notetype, nlength, ntime, ninstrument, nvolume):57 self.class_type = "Note"58 self.note_type = notetype59 self.length = nlength60 self.time = ntime61 self.instrument = ninstrument62 self.volume = nvolume63 # Markers are NYI64 # class Markers():65 # def __init__(self, time, setting, instrument, value, blend):66 # self.class_type = "Markers"67 # self.note_type = note_type68 # self.length = length69 # self.time = time70 # self.instrument = instrument71 # self.volume = volume72 # Will be added soon73 # class Settings():74 # def __init__(self, class_type, note_type, length, time, instrument, volume):75 # self.class_type = "Settings"76 # self.note_type = note_type77 # self.length = length78 # self.time = time79 # self.instrument = instrument80 # self.volume = volume8182 sheet = []83 note_number = -184 note_type = 085 length = 086 time = 087 instrument = 088 volume = 089 with open(sequenceloaddir, "r") as file:90 for line in file:91 line = line[:-1].strip().split(": ")92 if line[0] == "type":93 note_type = line[1]94 elif line[0] == "length":95 length = float(line[1])96 elif line[0] == "time":97 time = float(line[1])98 elif line[0] == "instrument":99 instrument = int(line[1])100 elif line[0] == "volume":101 volume = float(line[1])102 elif line[0] == "notes {":103 note_number += 1104 if note_number > 0:105 # print(note_type, length, time, instrument, volume)106 create_note(note_type, length, time, instrument, volume)107 sheet.append(Note(note_type, length, time, instrument, volume))108 note_type = 0109 length = 0110 time = 0111 instrument = 0112 volume = 0113 print(note_ids)114115116def playsequence():117 canvas.moveto(playlineid, 96, 0)118 moveline()119120def moveline():121 global play122 canvas.move(playlineid, 10, 0)123 print(list(canvas.find_overlapping(*canvas.bbox(playlineid, 'note'))))124 play = root.after(100, moveline)125126127def savefile():128 print('nyi')129130def opensequence():131 textfile = filedialog.askopenfilename(title="Open Sequence JSON File", filetypes=[('Text Sequences', '*.txt'), ('Text Sequences', '*.json')])132 loadsequence(textfile)133def importsequence():134 filetoparse = filedialog.askopenfilename(title="Open Sequence Binary File", filetypes=[('Binary Sequences', '*.sequence')])135 filetoparsename = (ntpath.basename(filetoparse)).split('.')[0]136 seqconvert.parsesequence(filetoparse)137 loadsequence('./converted/' + filetoparsename + '.sequence.txt') # yes I know this is jank138139def export_mp3():140 print('nyi')141142def export_wav():143 print('nyi')144145def export_ogg():146 print('nyi')147148def export_mid():149 print('nyi')150151def stopsequence():152 print(play)153 root.after_cancel(play)154 canvas.moveto(playlineid, 96, 0)155156157root = Tk()158159root.title('OfflineSequencer')160root.iconbitmap('./assets/icon.ico')161root.state("zoomed")162163menubar = Menu(root)164165filemenu = Menu(menubar, tearoff=0)166filemenu.add_command(label="New", command=clearall)167filemenu.add_command(label="Open", command=opensequence)168filemenu.add_command(label="Save", command=savefile)169filemenu.add_command(label="Import", command=importsequence)170filemenu.add_separator()171filemenu.add_command(label="Exit", command=root.quit)172menubar.add_cascade(label="File", menu=filemenu)173174exportmenu = Menu(menubar, tearoff=0)175exportmenu.add_command(label="Export MP3", command=export_mp3)176exportmenu.add_command(label="Export WAV", command=export_wav)177exportmenu.add_command(label="Export OGG", command=export_ogg)178exportmenu.add_command(label="Export MID", command=export_mid)179menubar.add_cascade(label="Export", menu=exportmenu)180181playmenu = Menu(menubar, tearoff=0)182playmenu.add_command(label="Current Sequence...", command=playsequence)183playmenu.add_command(label="Stop", command=stopsequence)184menubar.add_cascade(label="Play", menu=playmenu)185186root.config(menu=menubar)187188frame = Frame(root, width=1000000000, height=displayheight)189canvas = Canvas(frame, height=displayheight, width=1000000000, scrollregion=(0, 0, 1000000, 500))190hbar = Scrollbar(frame, orient=HORIZONTAL)191hbar.pack(side=BOTTOM, fill=X)192hbar.config(command=canvas.xview)193vbar = Scrollbar(frame, orient=VERTICAL)194vbar.pack(side=RIGHT, fill=Y)195vbar.config(command=canvas.yview)196canvas.config(xscrollcommand=hbar.set, yscrollcommand=vbar.set)197canvas.configure(bg='#45474C')198canvas.pack(side=LEFT, expand=True, fill=BOTH)199frame.pack(side=LEFT, expand=True, fill=BOTH)200w = 100201bw = 100202h = 0203canvasobjects = []204while w < 1000000:205 canvasobjects.append(canvas.create_line(w, 0, w, displayheight, width='1', tags='grid'))206 canvasobjects.append(canvas.create_line(bw, 0, bw, displayheight, width='2', tags='grid'))207 w = w + 16208 bw = bw + 256209210while h < displayheight:211 canvasobjects.append(canvas.create_line(0, h, 1000000, h, width='1', tags='grid'))212 h = h + 12213print(canvasobjects)214# 125080 and above are notes215playlineid = canvas.create_line(100, 0, 100, displayheight, width='2', fill='blue')216print(playlineid)217root.mainloop()218# canvas.move(playlineid, 100, 0)
...
serialization.py
Source:serialization.py
...27 return default28 def serialize_as_binary(self):29 Serialization.make_paths_for_file(self.data_file)30 dill.dump(obj=self.data, file=open(self.data_file, 'wb'))31 def deserialize_from_binary(self, default=None):32 try:33 self.data = dill.load(file=open(self.data_file, 'rb'))34 return self35 except (FileExistsError, FileNotFoundError):36 print('[Serialization] WARNING: {} not found,\n'37 '\treturned default value: {}'.format(self.data_file, default))38 return default39class GeneralSchema(Serialization, collections.MutableMapping):40 def __init__(self, data_file, main_key, **kwargs):41 """General Schema (like an abstract class)42 Creates something like this:43 .. code-block:: python44 md = GeneralSchema('~/app.config', 'app_name', version='0.1.0',45 'search-engine'='google.com')...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!