Best Python code snippet using localstack_python
test_msimanipulations.py
Source:test_msimanipulations.py  
...12    def setUp(self):13        self.msi = helpers.getFakeMsi()14        self.specialmsi = helpers.getFakeMsi()15        # set one pixel to special values16        self.specialValue = np.arange(self.specialmsi.get_image().shape[-1]) * 217        self.specialmsi.get_image()[2, 2, :] = self.specialValue18        # create a segmentation which sets all elements to invalid but the19        # one pixel with the special value20        self.segmentation = np.zeros(self.specialmsi.get_image().shape[0:-1])21        self.segmentation[2, 2] = 122    def tearDown(self):23        pass24    def test_apply_segmentation(self):25        mani.apply_segmentation(self.specialmsi, self.segmentation)26        validImageEntries = self.specialmsi.get_image() \27            [~self.specialmsi.get_image().mask]28        np.testing.assert_equal(validImageEntries, self.specialValue,29                        "image has been correctly segmented")30    def test_calculate_mean_spectrum(self):31        mani.calculate_mean_spectrum(self.specialmsi)32        np.testing.assert_equal(np.array([0.96, 2., 3.04, 4.08, 5.12]),33                                self.specialmsi.get_image(),34                        "mean spectrum is correctly calculated on image with " +35                        "no mask applied")36    def test_calculate_mean_spectrum_masked_image(self):37        mani.apply_segmentation(self.specialmsi, self.segmentation)38        mani.calculate_mean_spectrum(self.specialmsi)39        np.testing.assert_equal(self.specialValue, self.specialmsi.get_image(),40                        "mean spectrum is correctly calculated on image with " +41                        "mask applied")42    def test_interpolate(self):43        # create not sorted new wavelengths44        newWavelengths = np.array([4.0, 2.5, 3.5, 1.5])45        mani.interpolate_wavelengths(self.msi, newWavelengths)46        np.testing.assert_equal(newWavelengths, self.msi.get_wavelengths(),47                        "wavelengths correctly updated")48        # check if first image pixel was correctly calculated49        # (hopefully true for all then)50        np.testing.assert_equal(np.array([2.0, 3.5, 2.5, 4.5]),51                                self.msi.get_image()[0, 0, :],52                        "image elements correctly interpolated")53    def test_normalize_integration_times(self):54        old_shape = self.msi.get_image().shape55        integration_times = np.array([1., 2., 3., 4., 5.])56        self.msi.add_property({'integration times': integration_times})57        mani.normalize_integration_times(self.msi)58        np.testing.assert_equal(self.msi.get_image()[1, 3, :],59                            np.ones_like(integration_times),60                            "normalized integration times")61        np.testing.assert_equal(self.msi.get_properties()['integration times'],62                            np.ones_like(integration_times),63                            "integration time property set to ones")64        self.assertEqual(self.msi.get_image().shape, old_shape,65                        "shape did not change from normalizing")66    def test_normalize_integration_times_none_given(self):67        msi_copy = copy.deepcopy(self.msi)68        mani.normalize_integration_times(msi_copy)69        np.testing.assert_equal(msi_copy.get_image(), self.msi.get_image(),70                                "nothing change by normalizing without" + \71                                "integration times given")72    def test_dark_correction(self):73        desired_image_data = copy.copy(self.msi.get_image())74        desired_image_data -= 175        dark = copy.copy(self.msi)76        dark.set_image(np.ones_like(dark.get_image()))77        mani.dark_correction(self.msi, dark)78        np.testing.assert_equal(self.msi.get_image(),79                                       desired_image_data,80                                       "dark image correctly accounted for")81        np.testing.assert_equal(dark.get_image(),82                                       np.ones_like(dark.get_image()),83                        "dark image unchanged by dark correction")84    def test_dark_correction_with_single_value(self):85        desired_image_data = copy.copy(self.specialmsi.get_image())86        desired_image_data -= 187        dark = copy.copy(self.specialmsi)88        dark.set_image(np.ones_like(dark.get_image()))89        mani.calculate_mean_spectrum(dark)90        mani.dark_correction(self.specialmsi, dark)91        np.testing.assert_equal(self.specialmsi.get_image(),92                                       desired_image_data,93                "dark image correctly accounted for from singular dark value")94        np.testing.assert_equal(dark.get_image(),95                                       np.ones_like(dark.get_image()),96                "dark image unchanged by dark correction")97    def test_flatfield_correction(self):98        desired_image_data = np.ones_like(self.specialmsi.get_image())99        desired_image_data[2, 2, 0] = np.nan100        mani.flatfield_correction(self.specialmsi, self.specialmsi)101        np.testing.assert_equal(self.specialmsi.get_image(),102                                       desired_image_data,103                       "correct image by itself should lead to only 1s ")104    def test_flatfield_correction_differing_integration_times(self):105        MSI_INTEGRATION_TIME = 3.0106        FLATFIELD_INTEGRATION_TIME = 2.0107        desired_image_data = np.ones_like(self.specialmsi.get_image()) * \108             FLATFIELD_INTEGRATION_TIME / MSI_INTEGRATION_TIME109        desired_image_data[2, 2, 0] = np.nan110        self.specialmsi.add_property({"integration times":111                                      np.ones_like(112                                        self.specialmsi.get_image()[0, 0, :])113                                        * MSI_INTEGRATION_TIME})114        flatfield = copy.deepcopy(self.specialmsi)115        flatfield.add_property({"integration times":116                                np.ones_like(117                                    flatfield.get_image()[0, 0, :])118                                    * FLATFIELD_INTEGRATION_TIME})119        # for testing if flatfield does not changed by correction we copy it120        flatfield_copy = copy.deepcopy(flatfield)121        mani.flatfield_correction(self.specialmsi, flatfield_copy)122        np.testing.assert_almost_equal(self.specialmsi.get_image(),123                                       desired_image_data, 15,124                       "corrected image is a division of integration times")125        np.testing.assert_equal(flatfield.get_image(),126                                flatfield_copy.get_image(),127                                "flatfield doesn't change by correction")128    def test_flatfield_correction_with_single_value(self):129        desired_image_data = np.ones_like(self.msi.get_image())130        flatfield = copy.copy(self.msi)131        mani.calculate_mean_spectrum(flatfield)132        unchanged_flatfield = copy.deepcopy(flatfield)133        mani.flatfield_correction(self.msi, flatfield)134        np.testing.assert_equal(self.msi.get_image(),135                                       desired_image_data,136                "flatfield correctly accounted for from singular reference value")137        np.testing.assert_equal(flatfield, unchanged_flatfield,138                "flatfield not changed by algorithm")139    def test_image_correction(self):140        dark = copy.copy(self.msi)141        dark.set_image(np.ones_like(dark.get_image()) * 0.5)142        flatfield = copy.copy(self.msi)143        flatfield_copy = copy.deepcopy(flatfield)144        dark_copy = copy.deepcopy(dark)145        mani.image_correction(self.msi, flatfield, dark)146        np.testing.assert_equal(flatfield.get_image(),147                                flatfield_copy.get_image(),148                                "image correction didn't change flatfield")149        np.testing.assert_equal(dark.get_image(), dark_copy.get_image(),150                                "image correction didn't change dark image")151        np.testing.assert_almost_equal(self.msi.get_image(),152                                       np.ones_like(self.msi.get_image()),...constants.py
Source:constants.py  
...6bg_color = 200, 200, 2007screen = pygame.display.set_mode(size, pygame.FULLSCREEN)8pygame.display.set_caption("Quad Mayhem")9DBase('images.db')10normal_gas = Table('images').get_image(1)[1].convert()11toxic_gas = Table('images').get_image(2)[2].convert()12play_btn = Table('images').get_image(3)[3].convert()13quit_btn = Table('images').get_image(4)[4].convert()14ffa_btn = Table('images').get_image(5)[5].convert()15ctf_btn = Table('images').get_image(6)[6].convert()16tdm_btn = Table('images').get_image(7)[7].convert()17pause_btn = Table('images').get_image(8)[8].convert()18pause = Table('images').get_image(9)[9].convert()19hero_choicing = Table('images').get_image(10)[10].convert()20start_btn = Table('images').get_image(11)[11].convert()21not_in_btn = Table('images').get_image(12)[12].convert()22def_btn = Table('images').get_image(13)[13].convert()23attack_btn = Table('images').get_image(14)[14].convert()24not_in_btn_light = Table('images').get_image(15)[15].convert()25def_btn_light = Table('images').get_image(16)[16].convert()26attack_btn_light = Table('images').get_image(17)[17].convert()27wasd = Table('images').get_image(18)[18].convert()28arrows = Table('images').get_image(19)[19].convert()29gamepad1 = Table('images').get_image(20)[20].convert()30gamepad2 = Table('images').get_image(21)[21].convert()31wasd_light = Table('images').get_image(22)[22].convert()32arrows_light = Table('images').get_image(23)[23].convert()33gamepad1_light = Table('images').get_image(24)[24].convert()34gamepad2_light = Table('images').get_image(25)[25].convert()35control_choice = Table('images').get_image(26)[26].convert()36continue_but = Table('images').get_image(27)[27].convert()37hero_choicing2 = Table('images').get_image(28)[28].convert()38in_but = Table('images').get_image(29)[29].convert()39in_but_light = Table('images').get_image(30)[30].convert()40machine_gun = Table('images').get_image(31)[31].convert()41sub_machine_gun = Table('images').get_image(32)[32].convert()42semi_automatic_sniper_rifle = Table('images').get_image(33)[33].convert()43sniper_rifle = Table('images').get_image(58)[58].convert()44sniper_rifle_bullet = Table('images').get_image(59)[59].convert()45sub_machine_gun_bullet = Table('images').get_image(60)[60].convert()46semiauto_machinegun_bullet = Table('images').get_image(61)[61].convert()47portal = Table('images').get_image(62)[62].convert()48platform = Table('images').get_image(63)[63].convert()49team_flag = Table('images').get_image(64)[64].convert()50ammo = Table('images').get_image(65)[65].convert()51healing_box = Table('images').get_image(66)[66].convert()52jasper_protect = Table('images').get_image(67)[67].convert()53vincent_poison_ray = Table('images').get_image(68)[68].convert()54turret_of_guido = Table('images').get_image(69)[69].convert()55turret_of_guido_bullet = Table('images').get_image(70)[70].convert()56ffa_level = Table('images').get_image(71)[71].convert()57ctf_level = Table('images').get_image(72)[72].convert()58items_spawner = Table('images').get_image(73)[73].convert()59door_open = Table('images').get_image(74)[74].convert()60door_closed = Table('images').get_image(75)[75].convert()61bg = Table('images').get_image(76)[76].convert()62menu_bg = Table('images').get_image(77)[77].convert()63cur = Table('images').get_image(78)[78].convert()64mch1 = Table('images').get_image(79)[79].convert()65mch2 = Table('images').get_image(80)[80].convert()66mch3 = Table('images').get_image(81)[81].convert()67jasper_animation = list()68adam_animation = list()69vincent_animation = list()70guido_animation = list()71for i in range(35, 40):72    a = Table('images').get_image(i)[i].convert()73    a.set_colorkey('black')74    jasper_animation.append(a)75for i in range(41, 46):76    a = Table('images').get_image(i)[i].convert()77    a.set_colorkey('black')78    adam_animation.append(a)79for i in range(47, 52):80    a = Table('images').get_image(i)[i].convert()81    a.set_colorkey('black')82    vincent_animation.append(a)83for i in range(53, 58):84    a = Table('images').get_image(i)[i].convert()85    a.set_colorkey('black')86    guido_animation.append(a)87normal_gas.set_colorkey('white')88toxic_gas.set_colorkey('white')89pause_btn.set_colorkey('white')90machine_gun.set_colorkey('black')91sub_machine_gun.set_colorkey('black')92semi_automatic_sniper_rifle.set_colorkey('black')93sniper_rifle.set_colorkey('black')94ffa_level.set_colorkey('black')95ctf_level.set_colorkey('black')96turret_of_guido.set_colorkey('black')97vincent_poison_ray.set_colorkey('black')98healing_box.set_colorkey('black')...cat.py
Source:cat.py  
...9	font=("TkDefaultFont",13,"bold"))10log.update(idle=True)11sprites = {12	"default" : [13		base.get_image("cat/c1.png"),14		base.get_image("cat/c2.png"),15		base.get_image("cat/c3.png"),16		base.get_image("cat/c4.png"),17		base.get_image("cat/c5.png"),18		base.get_image("cat/c6.png"),19		base.get_image("cat/c7.png"),20		base.get_image("cat/c8.png"),21		base.get_image("cat/c9.png"),22		base.get_image("cat/c10.png"),23		base.get_image("cat/c11.png"),24		base.get_image("cat/c12.png"),25	],26	"staying" : [27		base.get_image("cat/b1.png"),28		base.get_image("cat/b2.png"),29		base.get_image("cat/b3.png"),30		base.get_image("cat/b4.png"),31		base.get_image("cat/b5.png"),32		base.get_image("cat/b6.png"),33	],34	"run1" : [35		base.get_image("cat/a1.png"),36		base.get_image("cat/a2.png"),37		base.get_image("cat/a3.png"),38		base.get_image("cat/a4.png"),39		base.get_image("cat/a5.png"),40		base.get_image("cat/a6.png"),41		base.get_image("cat/a7.png"),42		base.get_image("cat/a8.png"),43		base.get_image("cat/a9.png"),44		base.get_image("cat/a10.png"),45		base.get_image("cat/a11.png"),46		base.get_image("cat/a12.png"),47	],48	"run2" : [49		base.get_image("cat/d1.png"),50		base.get_image("cat/d2.png"),51		base.get_image("cat/d3.png"),52		base.get_image("cat/d4.png"),53		base.get_image("cat/d5.png"),54		base.get_image("cat/d6.png"),55		base.get_image("cat/d7.png"),56		base.get_image("cat/d8.png"),57		base.get_image("cat/d9.png"),58		base.get_image("cat/d10.png"),59		base.get_image("cat/d11.png"),60		base.get_image("cat/d12.png"),61		base.get_image("cat/d13.png"),62	]63}64log.style.update(text="lk")65log.update(idle=True)66CAT = game.Sprite(ca, top.get_width()/2,67	top.get_height()/2, tk_photo=sprites["default"][0])68CAT.states = sprites69def _(*args):70	if top.kmap.get("Left",False):71		CAT.to_state("default")72		CAT.next()73	elif top.kmap.get("Right",False):74		CAT.to_state("run1")75		CAT.next()...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!!
