Best Python code snippet using pyatom_python
Table.py
Source:Table.py
1import random2from enum import Enum3from threading import Lock4from src.components.Drawable import Drawable5from src.managers.ImageCache import ImageCache, Images6# status of the table7class Status(Enum):8 NotReady = 09 Ready = 110 Waiting = 211 Served = 312class Table(Drawable):13 def __init__(self, minX, maxX, minY, maxY, cellSize, offset):14 # call base class constructor15 super().__init__(0, 0, minX, maxX, minY, maxY, cellSize, offset)16 self.__status = Status.NotReady17 self.__order = []18 self.__guests = self.__getRandomGuests()19 self.__tableLock = Lock()20 @staticmethod21 def __getRandomGuests():22 possibleGuests = [Images.Guest1, Images.Guest2, Images.Guest3]23 guests = []24 guestCount = random.randint(1, len(possibleGuests))25 for _ in range(guestCount):26 guests.insert(0, possibleGuests[random.randint(0, len(possibleGuests) - 1)])27 return guests28 # waiter collects orders from table29 def getOrder(self):30 order = None31 if self.__tableLock.acquire(False):32 try:33 if self.isStatus(Status.Ready) and self.hasOrder():34 order = self.__order35 self.setOrder([])36 finally:37 self.__tableLock.release()38 return order39 def setOrder(self, order):40 self.__order = order41 def hasOrder(self):42 return [] != self.__order43 def isStatus(self, status):44 return status == self.__status45 def setStatus(self, status):46 self.__status = status47 def __getImage(self, imageKind):48 if imageKind in [Images.Guest1, Images.Guest2, Images.Guest3, Images.Plate]:49 size = int(self.getCellSize() / 3)50 else:51 size = int(1.4 * self.getCellSize())52 return ImageCache.getInstance().getImage(imageKind, size, size)53 # draws only table54 def draw(self, screen):55 xBase = self.getX() * self.getCellSize() + self.getOffset()56 yBase = self.getY() * self.getCellSize() + self.getOffset()57 tableXYOffset = int(0.2 * self.getCellSize())58 screen.blit(self.__getImage(Images.Table), (xBase - tableXYOffset, yBase - tableXYOffset))59 # draws images related to the status of a table60 # the method is called in the second turn when all tables are already painted61 def drawAux(self, screen):62 xBase = self.getX() * self.getCellSize() + self.getOffset()63 yBase = self.getY() * self.getCellSize() + self.getOffset()64 guest1XOffset = 065 guest2XOffset = int((1 / 3) * self.getCellSize())66 guest3XOffset = int((2 / 3) * self.getCellSize())67 guest4XOffset = int((1 / 9) * self.getCellSize())68 guest5XOffset = int((5 / 9) * self.getCellSize())69 guestsYOffset = int(0.1 * self.getCellSize())70 tableXYOffset = int(0.2 * self.getCellSize())71 if len(self.__guests) == 1:72 screen.blit(self.__getImage(self.__guests[0]), (xBase + guest2XOffset, yBase - guestsYOffset))73 elif len(self.__guests) == 2:74 screen.blit(self.__getImage(self.__guests[0]), (xBase + guest4XOffset, yBase - guestsYOffset))75 screen.blit(self.__getImage(self.__guests[1]), (xBase + guest5XOffset, yBase - guestsYOffset))76 elif len(self.__guests) == 3:77 screen.blit(self.__getImage(self.__guests[0]), (xBase + guest1XOffset, yBase - guestsYOffset))78 screen.blit(self.__getImage(self.__guests[1]), (xBase + guest2XOffset, yBase - guestsYOffset))79 screen.blit(self.__getImage(self.__guests[2]), (xBase + guest3XOffset, yBase - guestsYOffset))80 if self.isStatus(Status.NotReady):81 screen.blit(self.__getImage(Images.Menu), (xBase - tableXYOffset, yBase - tableXYOffset))82 elif self.isStatus(Status.Ready):83 screen.blit(self.__getImage(Images.Check), (xBase - tableXYOffset, yBase - tableXYOffset))84 elif self.isStatus(Status.Waiting):85 platesYOffset = int(0.3 * self.getCellSize())86 imagePlate = self.__getImage(Images.Plate)87 if len(self.__guests) == 1:88 screen.blit(imagePlate, (xBase + guest2XOffset, yBase + platesYOffset))89 elif len(self.__guests) == 2:90 screen.blit(imagePlate, (xBase + guest4XOffset, yBase + platesYOffset))91 screen.blit(imagePlate, (xBase + guest5XOffset, yBase + platesYOffset))92 elif len(self.__guests) == 3:93 screen.blit(imagePlate, (xBase + guest1XOffset, yBase + platesYOffset))94 screen.blit(imagePlate, (xBase + guest2XOffset, yBase + platesYOffset))...
wumpus_draw.py
Source:wumpus_draw.py
1from graphics import *2from wumpus_data import *3from wumpus_logic import *45# Implement drawWumpus, drawGold, drawBreeze, drawStench, and updateDisplay here67def initializeGraphics(width, height, cell_size):8 global HIDDEN, VISIBLE9 global WUMPUS_PIXMAP, PIT_PIXMAP, GOLD_PIXMAP, STENCH_PIXMAP, BREEZE_PIXMAP10 global ADVENTURER_GOLD_PIXMAP, ADVENTURER_DEAD_PIXMAP11 global ADVENTURER_ARROW_PIXMAP, ADVENTURER_NO_ARROW_PIXMAP1213 window = GraphWin("Find the Gold", width*cell_size, height*cell_size)14 HIDDEN = color_rgb(100, 100, 100)15 VISIBLE = color_rgb(200, 200, 200)16 WUMPUS_PIXMAP = "wumpus_img.gif"17 PIT_PIXMAP = "pit_img.gif"18 GOLD_PIXMAP = "gold_img.gif"19 STENCH_PIXMAP = "stench_img.gif"20 BREEZE_PIXMAP = "breeze_img.gif"21 ADVENTURER_GOLD_PIXMAP = "adventurer_gold_img.gif"22 ADVENTURER_DEAD_PIXMAP = "adventurer_dead_img.gif"23 ADVENTURER_ARROW_PIXMAP = "adventurer_arrow_img.gif"24 ADVENTURER_NO_ARROW_PIXMAP = "adventurer_no_arrow_img.gif"25 return window2627def drawCell(window, data, x, y):28 cell_size = getCellSize(data)29 b_visible = cellIsVisible(data, x, y)30 p1 = Point(x*cell_size, y*cell_size)31 p2 = Point((x+1)*cell_size, (y+1)*cell_size)32 cell = Rectangle(p1, p2)33 if b_visible:34 cell.setFill(VISIBLE)35 cell.draw(window)36 drawPit(window, data, x, y)37 drawWumpus(window, data, x, y)38 drawGold(window, data, x, y)39 drawBreeze(window, data, x, y)40 drawStench(window, data, x, y)41 else:42 cell.setFill(HIDDEN)43 cell.draw(window)4445def drawAdventurer(window, data, x, y):46 cell_size = getCellSize(data)47 have_gold = getHaveGold(data)48 have_arrow = getHaveArrow(data)49 is_alive = getIsAlive(data)50 adventurer_point = Point((x+.25)*cell_size, (y+.25)*cell_size)51 if not is_alive:52 ai = Image(adventurer_point, ADVENTURER_DEAD_PIXMAP)53 elif have_gold:54 ai = Image(adventurer_point, ADVENTURER_GOLD_PIXMAP)55 elif have_arrow:56 ai = Image(adventurer_point, ADVENTURER_ARROW_PIXMAP)57 else:58 ai = Image(adventurer_point, ADVENTURER_NO_ARROW_PIXMAP)59 ai.draw(window)6061def drawPit(window, data, x, y):62 cell_size = getCellSize(data)63 contains = cellContainsPit(data, x, y)64 point = Point((x+.75)*cell_size, (y+.25)*cell_size)65 if contains:66 img = Image(point, PIT_PIXMAP)67 img.draw(window)6869def updateDisplay(window, data, ax, ay):70 (width, height) = getDimensions(data)71 for y in range(0, height):72 for x in range(0, width):73 drawCell(window, data, x, y)74 drawAdventurer(window, data, ax, ay) 7576def drawWumpus(window, data, x, y):77 cell_size = getCellSize(data)78 contains = cellContainsWumpus(data, x, y)79 point = Point((x+.75)*cell_size, (y+.75)*cell_size)80 if contains:81 img = Image(point, WUMPUS_PIXMAP)82 img.draw(window)8384def drawGold(window, data, x, y):85 cell_size = getCellSize(data)86 contains = cellContainsGold(data, x, y)87 point = Point((x+.25)*cell_size, (y+.75)*cell_size)88 if contains:89 img = Image(point, GOLD_PIXMAP)90 img.draw(window)9192def drawBreeze(window, data, x, y):93 cell_size = getCellSize(data)94 pit = neighborCellContainsPit(data, x, y)95 point = Point((x+.75)*cell_size, (y+.25)*cell_size)96 if pit:97 img = Image(point, BREEZE_PIXMAP)98 img.draw(window)99100def drawStench(window, data, x, y):101 cell_size = getCellSize(data)102 wumpus = neighborCellContainsWumpus(data, x, y)103 point = Point((x+.75)*cell_size, (y+.75)*cell_size)104 if wumpus:105 img = Image(point, STENCH_PIXMAP)106 img.draw(window)
...
dss_test_utility.py
Source:dss_test_utility.py
1from hec.heclib.grid import GridData2from hec.heclib.grid import GridUtilities3from hec.heclib.dss import HecDSSFileAccess4from jarray import zeros5from hec.lang import DSSPathString6def assertFloatEqual(o1, o2,tolerance, msg):7 if abs(o2-o2) > tolerance:8 raise Exception(msg+" \n"+str(o1)+" is not equal to "+str(o2))9def assertNotEquals(o1, o2,msg):10 if o1 == o2:11 raise Exception(msg+" \n"+str(o1)+" is not equal to "+str(o2))12def assertEqual(o1, o2,msg):13 if o1 != o2:14 raise Exception(msg+" \n"+str(o1)+" is not equal to "+str(o2))15def ReadGrid(dssFile, path):16 status = zeros(1,'i')17 18 rval = GridUtilities.retrieveGridFromDss(dssFile, path, status)19 if status[0] !=0:20 print("error reading grid "+path+" in file '"+dssFile)21 22 return rval23def compare_grids(dssFile1, dssFile2, path):24 gd1 = ReadGrid(dssFile1, path)25 gd2 = ReadGrid(dssFile2, path)26 gd1.updateStatistics()27 gd2.updateStatistics()28 info1 = gd1.getGridInfo()29 info2 = gd2.getGridInfo()30 assertEqual(info1.getGridType(), info2.getGridType(), "getGridType() " + path)31 assertEqual(info1.getDataUnits(), info2.getDataUnits(), "getDataUnits" + path)32 assertEqual(info1.getDataTypeName(), info2.getDataTypeName(), "getDataTypeName" + path)33 dssPath = DSSPathString(path)34 #// empty path in DSS6 defaults to 31 December 1899, 00:00,35 #// empty path in DSS7 is blank36 if dssPath.getDPart().strip() != "":37 assertEqual(info1.getEndTime(), info2.getEndTime(), "getEndTime()" + path)38 if dssPath.getEPart().strip() != "":39 assertEqual(info1.getStartTime(), info2.getStartTime(), "getStartTime()" + path)40 assertEqual(info1.getNumberOfCellsX(), info2.getNumberOfCellsX(), "getNumberOfCellsX()" + path)41 assertEqual(info1.getNumberOfCellsY(), info2.getNumberOfCellsY(), "getNumberOfCellsY()" + path)42 assertEqual(info1.getRangeNum(), info2.getRangeNum(), "getRangeNum()" + path)43 assertFloatEqual(info1.getMaxDataValue(), info2.getMaxDataValue(), 0.01, "getMaxDataValue()" + path)44 assertFloatEqual(info1.getMinDataValue(), info2.getMinDataValue(), 0.01, "getMinDataValue()" + path)45 assertFloatEqual(info1.getMeanDataValue(), info2.getMeanDataValue(), 0.01, "getMeanDataValue()" + path)46 assertNotEquals(0,info1.getCellSize(),"cellSize record 1")47 assertNotEquals(0,info2.getCellSize(),"cellSize record 2")48 assertEqual(info1.getCellSize(), info2.getCellSize(), "getCellSize()" + path)49 assertEqual(info1.getLowerLeftCellX(), info2.getLowerLeftCellX(), "getLowerLeftCellX()" + path)50 assertEqual(info1.getLowerLeftCellY(), info2.getLowerLeftCellY(), "getLowerLeftCellY()" + path)51 assertEqual(info1.getRangeNum(), info2.getRangeNum(), "getRangeNum" + path)52 for i in range(info1.getRangeNum() ):53 assertFloatEqual(info1.getRangeLimitTable()[i], info2.getRangeLimitTable()[i], 0.001, "getRangeLimitTable()[" + str(i) + "]" + path)54 55 assertEqual(info1.getSpatialReferenceSystem(), info2.getSpatialReferenceSystem(), "getSpatialReferenceSystem()" + path)56 data1 = gd1.getData()57 data2 = gd2.getData()58 tolerance = 0.00159 print("len of data = "+str(len(data1)))60# for i in range(len(data1)):61 i=062 while( i<len(data1)):63 tolerance = 0.01 if data1[i]>10 else 0.00164 assertFloatEqual(data1[i], data2[i], tolerance, "comparing grid float values [" + str(i) + "] " + path)...
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!!