How to use update_images method in localstack

Best Python code snippet using localstack_python

test_main.py

Source:test_main.py Github

copy

Full Screen

1import base642import unittest3import pytest4from tag_bot.main import UpdateImageTags, assert_images_info_input, split_str_to_list5from tag_bot.yaml_parser import YamlParser6yaml = YamlParser()7class TestUpdateImageTags(unittest.TestCase):8 def test_update_config_singleuser(self):9 update_images = UpdateImageTags(10 "octocat/octocat",11 "ThIs_Is_A_t0k3n",12 "config/config.yaml",13 [".singleuser.image"],14 )15 update_images.config = {16 "singleuser": {17 "image": {"name": "image_owner/image_name", "tag": "image_tag"}18 }19 }20 update_images.images_to_update = ["image_owner/image_name"]21 update_images.image_tags = {22 "image_owner/image_name": {23 "current": "image_tag",24 "latest": "new_image_tag",25 "path": ".singleuser.image.tag",26 }27 }28 expected_output = {29 "singleuser": {30 "image": {"name": "image_owner/image_name", "tag": "new_image_tag"},31 }32 }33 expected_output = yaml.object_to_yaml_str(expected_output).encode("utf-8")34 expected_output = base64.b64encode(expected_output).decode("utf-8")35 result = update_images.update_config()36 self.assertEqual(result, expected_output)37 def test_update_config_profileList(self):38 update_images = UpdateImageTags(39 "octocat/octocat",40 "ThIs_Is_A_t0k3n",41 "config/config.yaml",42 [".singleuser.profileList[0].kubespawner_override.image"],43 )44 update_images.config = {45 "singleuser": {46 "profileList": [47 {48 "kubespawner_override": {49 "image": "image_owner/image_name:image_tag"50 }51 }52 ]53 }54 }55 update_images.images_to_update = ["image_owner/image_name"]56 update_images.image_tags = {57 "image_owner/image_name": {58 "current": "image_tag",59 "latest": "new_image_tag",60 "path": ".singleuser.profileList[0].kubespawner_override.image",61 }62 }63 expected_output = {64 "singleuser": {65 "profileList": [66 {67 "kubespawner_override": {68 "image": "image_owner/image_name:new_image_tag"69 }70 }71 ]72 }73 }74 expected_output = yaml.object_to_yaml_str(expected_output).encode("utf-8")75 expected_output = base64.b64encode(expected_output).decode("utf-8")76 result = update_images.update_config()77 self.assertEqual(result, expected_output)78 def test_update_config_both(self):79 update_images = UpdateImageTags(80 "octocat/octocat",81 "ThIs_Is_A_t0k3n",82 "config/config.yaml",83 [84 ".singleuser.image",85 ".singleuser.profileList[0].kubespawner_override.image",86 ],87 )88 update_images.config = {89 "singleuser": {90 "image": {"name": "image_owner/image_name1", "tag": "image_tag1"},91 "profileList": [92 {93 "kubespawner_override": {94 "image": "image_owner/image_name2:image_tag2"95 }96 }97 ],98 }99 }100 update_images.images_to_update = [101 "image_owner/image_name1",102 "image_owner/image_name2",103 ]104 update_images.image_tags = {105 "image_owner/image_name1": {106 "current": "image_tag1",107 "latest": "new_image_tag1",108 "path": ".singleuser.image.tag",109 },110 "image_owner/image_name2": {111 "current": "image_tag2",112 "latest": "new_image_tag2",113 "path": ".singleuser.profileList[0].kubespawner_override.image",114 },115 }116 expected_output = {117 "singleuser": {118 "image": {"name": "image_owner/image_name1", "tag": "new_image_tag1"},119 "profileList": [120 {121 "kubespawner_override": {122 "image": "image_owner/image_name2:new_image_tag2"123 }124 }125 ],126 }127 }128 expected_output = yaml.object_to_yaml_str(expected_output).encode("utf-8")129 expected_output = base64.b64encode(expected_output).decode("utf-8")130 result = update_images.update_config()131 self.assertEqual(result, expected_output)132def test_split_str_to_list_simple():133 test_str1 = "label1,label2"134 test_str2 = "label1 , label2"135 expected_output = ["label1", "label2"]136 result1 = split_str_to_list(test_str1, split_char=",")137 result2 = split_str_to_list(test_str2, split_char=",")138 assert result1 == expected_output139 assert result2 == expected_output140 assert result1 == result2141def test_split_str_to_list_complex():142 test_str1 = "type: feature,impact: low"143 test_str2 = "type: feature , impact: low"144 expected_output = ["type: feature", "impact: low"]145 result1 = split_str_to_list(test_str1, split_char=",")146 result2 = split_str_to_list(test_str2, split_char=",")147 assert result1 == expected_output148 assert result2 == expected_output149 assert result1 == result2150def test_assert_images_info_input_pass():151 images_info = [{"values_path": ".singleuser.image"}]152 assert_images_info_input(images_info)153def test_assert_images_info_input_fail_1():154 images_info = {"values_path": ".singleuser.image"}155 with pytest.raises(AssertionError):156 assert_images_info_input(images_info)157def test_assert_images_info_input_fail_2():158 images_info = ["values_paths", ".singleuser.image"]159 with pytest.raises(AssertionError):160 assert_images_info_input(images_info)161def test_assert_images_info_input_fail_3():162 images_info = [{"values_paths": ".singleuser.image"}]163 with pytest.raises(AssertionError):164 assert_images_info_input(images_info)165def test_assert_images_info_input_fail_4():166 images_info = [{"values_path": 42}]167 with pytest.raises(AssertionError):168 assert_images_info_input(images_info)169if __name__ == "__main__":...

Full Screen

Full Screen

hsv_finder_img.py

Source:hsv_finder_img.py Github

copy

Full Screen

...24 global hue_h25 if pos>255:26 pos=25527 hue_h = pos28 update_images()29 30def sat_trackbar_handler(pos):31 global saturation_h32 if pos>255:33 pos=25534 saturation_h = pos35 update_images()36 37def val_trackbar_handler(pos):38 global value_h39 if pos>255:40 pos=25541 value_h = pos42 update_images()43def hue_trackbar_handler2(pos):44 global hue_l45 if pos<0:46 pos=047 hue_l = pos48 update_images()49 50def sat_trackbar_handler2(pos):51 global saturation_l52 if pos<0:53 pos=054 saturation_l = pos55 update_images()56 57def val_trackbar_handler2(pos):58 global value_l59 if pos<0:60 pos=061 value_l = pos62 update_images()63 64def create_empty_image(height, width, color):65 global img_color66 img_color = np.array(np.ones((height, width, 3), np.uint8) * color, dtype=np.uint8)67 68def color_a_quad(quad_no, color, color_format='bgr'):69 if color_format == 'rgb':70 color.reverse()71 for h in range(QUADS[quad_no][0], QUADS[quad_no][1]):72 for w in range(QUADS[quad_no][2], QUADS[quad_no][3]):73 img_color[h][w] = np.uint8(color)74def pick_color(event,x,y,flags,param):75 global hue_l,hue_h,saturation_l,saturation_h,value_l,value_h76 if event == cv2.EVENT_LBUTTONDOWN:77 pixel = img_hsv[y,x]78 #you might want to adjust the ranges(+-10, etc):79 if pixel[0] <hue_l: 80 hue_l=pixel[0]-1081 hue_trackbar_handler2(hue_l)82 if pixel[1] <saturation_l: 83 saturation_l=pixel[1]-1084 sat_trackbar_handler2(saturation_l)85 if pixel[2] <value_l: 86 value_l=pixel[2]-2087 val_trackbar_handler2(value_l)88 if pixel[0] >hue_h: 89 hue_h=pixel[0]+1090 hue_trackbar_handler(hue_h)91 if pixel[1] >saturation_h: 92 saturation_h=pixel[1]+1093 sat_trackbar_handler(saturation_h)94 if pixel[2] >value_h: 95 value_h=pixel[2]+2096 val_trackbar_handler(value_h)97def update_images():98 #print "Position Changes"99 cv2.setTrackbarPos('Hue Lower', 'yo_hsv_bars',hue_l)100 cv2.setTrackbarPos('Saturation Lower', 'yo_hsv_bars',saturation_l)101 cv2.setTrackbarPos('Value Lower', 'yo_hsv_bars',value_l)102 cv2.setTrackbarPos('Hue Upper', 'yo_hsv_bars',hue_h)103 cv2.setTrackbarPos('Saturation Upper', 'yo_hsv_bars',saturation_h)104 cv2.setTrackbarPos('Value Upper', 'yo_hsv_bars',value_h)105 hsv_upper = np.array([hue_h, saturation_h, value_h], np.uint8)106 hsv_lower = np.array([hue_l, saturation_l, value_l], np.uint8)107 hsv_color_h = cv2.cvtColor(np.uint8([[[hue_h, saturation_h, value_h]]]), cv2.COLOR_HSV2BGR)108 hsv_color_l = cv2.cvtColor(np.uint8([[[hue_l, saturation_l, value_l]]]), cv2.COLOR_HSV2BGR)109 color_a_quad(1, hsv_color_h)110 color_a_quad(3, hsv_color_l)111 img_range = cv2.inRange(img_hsv, hsv_lower, hsv_upper)112 bgr_val = str(hsv_color_h[0][0][0]) + ',' + str(hsv_color_h[0][0][1]) + ',' + str(hsv_color_h[0][0][2])113 rgb_val = str(hsv_color_h[0][0][2]) + ',' + str(hsv_color_h[0][0][1]) + ',' + str(hsv_color_h[0][0][0])114 cv2.putText(img_color, 'BGR: '+bgr_val, (350, 100), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255))115 cv2.putText(img_color, 'RGB: '+rgb_val, (350, 125), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255))116 cv2.imshow('Colors', img_color)117 cv2.imshow('Image', img_range)118 119if __name__ == "__main__":120 cv2.namedWindow('yo_hsv_bars')121 cv2.namedWindow('hsv')122 cv2.createTrackbar('Hue Lower', 'yo_hsv_bars', 0, 179, hue_trackbar_handler2)123 cv2.createTrackbar('Saturation Lower', 'yo_hsv_bars', 0, 255, sat_trackbar_handler2)124 cv2.createTrackbar('Value Lower', 'yo_hsv_bars', 0, 255, val_trackbar_handler2)125 cv2.createTrackbar('Hue Upper', 'yo_hsv_bars', 0, 179, hue_trackbar_handler)126 cv2.createTrackbar('Saturation Upper', 'yo_hsv_bars', 0, 255, sat_trackbar_handler)127 cv2.createTrackbar('Value Upper', 'yo_hsv_bars', 0, 255, val_trackbar_handler)128 cv2.setMouseCallback('hsv', pick_color)129 create_empty_image(HEIGHT, WIDTH, [0, 0, 255])130 np.shape(img_color)131 img_bk = img_color.copy()132 cv2.imshow('Colors', img_color)133 img_f = cv2.imread(sys.argv[1])134 cv2.imshow('hsv',img_f)135 img_hsv = cv2.cvtColor(img_f, cv2.COLOR_BGR2HSV)136 update_images()137 while 'q' != chr(cv2.waitKey(0) & 0xFF):138 pass...

Full Screen

Full Screen

window_level.py

Source:window_level.py Github

copy

Full Screen

1from PyQt4.QtCore import *2from PyQt4.QtGui import *3import ui_WLDialog4class WLDialog(QDialog, ui_WLDialog.Ui_Dialog):5 """Dialog for adjusting window/level for images and overlays"""6 update_images = pyqtSignal()7 def __init__(self, image, overlay,parent=None):8 # Invoke parent's method9 super(WLDialog, self).__init__(parent)10 self.image = image11 #12 # <------------------------ Gui setup ----------------------->13 #14 self.setupUi(self)15 # set intervals for controls16 c_inf, c_sup = self.image.pixel_thresholds()17 self.sld_center.setMinimum(c_inf)18 self.sld_center.setMaximum(c_sup)19 self.spb_center.setMinimum(c_inf)20 self.spb_center.setMaximum(c_sup)21 # No need to change lower limit of window associated controls22 self.sld_window.setMaximum(c_sup)23 self.spb_window.setMaximum(c_sup)24 # set signals for update images25 self.sld_center.valueChanged.connect(self.update_center)26 self.sld_window.valueChanged.connect(self.update_window)27 # set control values28 self.center0 = self.image.attributes['center']29 self.center = self.center030 self.window0 = self.image.attributes['window']31 self.sld_center.setValue(self.center0)32 self.sld_window.setValue(self.window0)33 if overlay is not None:34 self.overlay = overlay35 self.enable_controls()36 self.sld_min_value.setMinimum(self.overlay.lowest_value)37 self.sld_min_value.setMaximum(self.overlay.highest_value)38 self.spb_min_value.setMinimum(self.overlay.lowest_value)39 self.spb_min_value.setMaximum(self.overlay.highest_value)40 self.sld_min_value.setValue(self.overlay.low_value)41 self.low0 = self.overlay.low_value42 self.high0 = self.overlay.high_value43 self.sld_max_value.setMinimum(self.overlay.lowest_value)44 self.sld_max_value.setMaximum(self.overlay.highest_value)45 self.spb_max_value.setMinimum(self.overlay.lowest_value)46 self.spb_max_value.setMaximum(self.overlay.highest_value)47 self.sld_max_value.setValue(self.overlay.high_value)48 self.alpha0 = self.overlay.alpha49 self.sld_alpha.setValue(self.alpha0)50 # some signals to control intervals51 self.sld_min_value.valueChanged.connect(self.update_low_value)52 self.sld_max_value.valueChanged.connect(self.update_high_value)53 self.sld_alpha.valueChanged.connect(self.update_alpha)54 def update_center(self, new_center):55 self.center = new_center56 self.image.attributes['center'] = new_center57 self.update_window(self.sld_window.value())58 self.update_images.emit()59 def update_window(self, new_window):60 # See notes about window and center choices61 # w_sup = min(abs(self.center - self.sld_center.minimum()), abs(self.center - self.sld_center.maximum()))62 # if new_window > w_sup:63 # self.sld_window.setValue(w_sup)64 # new_window = w_sup65 self.image.attributes['window'] = new_window66 self.update_images.emit()67 def update_low_value(self, new_low_value):68 if new_low_value > self.sld_max_value.value():69 self.sld_min_value.setValue(self.sld_max_value.value())70 self.overlay.set_threshold(new_low_value, self.sld_max_value.value())71 self.update_images.emit()72 def update_high_value(self, new_high_value):73 if new_high_value < self.sld_min_value.value():74 self.sld_min_value.setValue(self.sld_min_value.value())75 self.overlay.set_threshold(self.sld_min_value.value(), new_high_value)76 self.update_images.emit()77 def update_alpha(self, new_alpha):78 self.overlay.set_alpha(new_alpha)79 self.update_images.emit()80 def enable_controls(self):81 self.lb_overlay.setEnabled(True)82 self.sld_min_value.setEnabled(True)83 self.spb_min_value.setEnabled(True)84 self.sld_max_value.setEnabled(True)85 self.spb_max_value.setEnabled(True)86 self.sld_alpha.setEnabled(True)...

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