How to use set_checks method in pandera

Best Python code snippet using pandera_python

anagram.py

Source:anagram.py Github

copy

Full Screen

...86 self.ui.txtSolutionOrig.setText(self.anagram.solution[common.editor_config.lang_orig])87 self.ui.txtExtraTrans.setText(self.anagram.extra[common.editor_config.lang_trans])88 self.ui.txtExtraOrig.setText(self.anagram.extra[common.editor_config.lang_orig])89 90 self.set_checks(CHK_TYPE.Trans, CHK_DIFF.Easy, self.anagram.easy)91 self.set_checks(CHK_TYPE.Trans, CHK_DIFF.Norm, self.anagram.normal)92 self.set_checks(CHK_TYPE.Trans, CHK_DIFF.Hard, self.anagram.hard)93 94 self.set_checks(CHK_TYPE.Orig, CHK_DIFF.Easy, self.anagram.easy_orig)95 self.set_checks(CHK_TYPE.Orig, CHK_DIFF.Norm, self.anagram.normal_orig)96 self.set_checks(CHK_TYPE.Orig, CHK_DIFF.Hard, self.anagram.hard_orig)97 98 # The translation side is updated automatically because the text box changes.99 self.update_checks(CHK_TYPE.Orig)100 self.update_preview()101 102 ##############################################################################103 ### @fn save()104 ### @desc Save the anagram dat file, with backups/changes.105 ##############################################################################106 def save(self):107 108 source = self.anagram.filename109 filename = os.path.basename(self.anagram.filename)110 111 # First, make the backup.112 self.anagram.backup()113 114 # Then save a copy of our changes for easy access.115 change_file = os.path.join(common.editor_config.changes_dir, filename)116 self.anagram.save(change_file)117 118 # Then save for real.119 self.anagram.save()120 121 ##############################################################################122 ### @fn get_check()123 ### @desc Returns the checkbox object for a type, difficulty, and value.124 ##############################################################################125 def get_check(self, type, difficulty, value):126 if not type == CHK_TYPE.Orig and not type == CHK_TYPE.Trans:127 return None128 129 if not difficulty == CHK_DIFF.Easy and not difficulty == CHK_DIFF.Norm and not difficulty == CHK_DIFF.Hard:130 return None131 132 if not value in CHK_VAL:133 return None134 135 return vars(self.ui)["chk%s%s%d" % (str(type), str(difficulty), value)]136 137 ##############################################################################138 ### @fn update_preview()139 ### @desc Updates the preview image.140 ##############################################################################141 def update_preview(self):142 143 image = draw_anagram(self.anagram)144 pixmap = QtGui.QPixmap.fromImage(image)145 self.ui.lblPreview.setPixmap(pixmap)146 147 ##############################################################################148 ### @fn check_clicked()149 ### @desc What happens when a check is clicked.150 ##############################################################################151 def check_clicked(self):152 153 self.store_checks()154 self.update_preview()155 156 ##############################################################################157 ### @fn store_checks()158 ### @desc Take the check boxes and store their values in our anagram.159 ##############################################################################160 def store_checks(self):161 162 if not self.anagram == None:163 self.anagram.easy = self.checks_to_list(CHK_TYPE.Trans, CHK_DIFF.Easy)164 self.anagram.normal = self.checks_to_list(CHK_TYPE.Trans, CHK_DIFF.Norm)165 self.anagram.hard = self.checks_to_list(CHK_TYPE.Trans, CHK_DIFF.Hard)166 167 ##############################################################################168 ### @fn set_checks()169 ### @desc Checks/unchecks the checkboxes based on a list of shown letters.170 ##############################################################################171 def set_checks(self, type, difficulty, shown):172 173 for i in range(1, 16):174 checked = False175 if not shown == None and i in shown:176 checked = True177 178 self.get_check(type, difficulty, i).setChecked(checked)179 180 ##############################################################################181 ### @fn checks_to_list(type, difficulty)182 ### @desc Converts the check boxes into a list of shown letters.183 ##############################################################################184 def checks_to_list(self, type, difficulty):185 text = ""...

Full Screen

Full Screen

test_consul_healthchecks.py

Source:test_consul_healthchecks.py Github

copy

Full Screen

...38 'consul_healthchecks': {39 check_id: check40 }41 }42 def set_checks(self, checks):43 self.appspec = {44 'consul_healthchecks': checks45 }46 def set_platform(self, platform):47 self.platform = platform48class TestHealthChecks(unittest.TestCase):49 def setUp(self):50 self.deployment = MockDeployment()51 self.tested_fn = RegisterConsulHealthChecks()52 def test_failing_check(self):53 check = {54 'type': 'unknown',55 'name': 'check_name'56 }57 self.deployment.set_check('check_failing', check)58 with self.assertRaisesRegexp(DeploymentError, 'only.*check types are supported'):59 self.tested_fn._run(self.deployment)60 def test_missing_name_field(self):61 check = {62 'type': 'http',63 'name': 'check_name'64 }65 self.deployment.set_check('check_failing', check)66 with self.assertRaisesRegexp(DeploymentError, 'is missing field'):67 self.tested_fn._run(self.deployment)68 def test_missing_http_field(self):69 check = {70 'type': 'http',71 'name': 'Missing http'72 }73 self.deployment.set_check('check_failing', check)74 with self.assertRaisesRegexp(DeploymentError, 'is missing field \'url\''):75 self.tested_fn._run(self.deployment)76 def test_missing_http_tls_skip_verify_field(self):77 check = {78 'type': 'http',79 'name': 'Missing tls_skip_verify',80 'url': 'http://localhost',81 'interval': 1082 }83 self.deployment.set_check('check_successful', check)84 self.deployment.consul_api = MagicMock()85 self.tested_fn._run(self.deployment)86 self.deployment.consul_api.register_http_check.assert_called_once_with('my-mock-service', 'my-mock-service:check_successful', 'Missing tls_skip_verify', 'http://localhost', 10, False)87 88 def test_http_tls_skip_verify_field(self):89 check = {90 'type': 'http',91 'name': 'Test tls_skip_verify',92 'url': 'http://localhost',93 'interval': 10,94 'tls_skip_verify': True95 }96 self.deployment.set_check('check_successful', check)97 self.deployment.consul_api = MagicMock()98 self.tested_fn._run(self.deployment)99 self.deployment.consul_api.register_http_check.assert_called_once_with('my-mock-service', 'my-mock-service:check_successful', 'Test tls_skip_verify', 'http://localhost', 10, True)100 def test_case_insensitive_id_conflict(self):101 checks = {102 'check_1': {103 'type': 'http',104 'name': 'Missing http 1'105 },106 'cheCK_1': {107 'type': 'http',108 'name': 'Missing http 2'109 }110 }111 self.deployment.set_checks(checks)112 with self.assertRaisesRegexp(DeploymentError, 'health checks require unique ids'):113 self.tested_fn._run(self.deployment)114 def test_case_insensitive_name_conflict(self):115 checks = {116 'check_1': {117 'type': 'http',118 'name': 'Missing http'119 },120 'check_2': {121 'type': 'http',122 'name': 'Missing http'123 }124 }125 self.deployment.set_checks(checks)126 with self.assertRaisesRegexp(DeploymentError, 'health checks require unique names'):127 self.tested_fn._run(self.deployment)128 @patch('os.stat')129 @patch('os.chmod')130 @patch('os.path.exists', return_value=True)131 def test_script_check_registration(self, stat, chmod, exists):132 checks = {133 'test_check': self.create_check(True, 'test-script', 'test-script.py', '10')134 }135 self.deployment.set_checks(checks)136 self.deployment.consul_api = MagicMock()137 with patch('agent.deployment_stages.consul_healthchecks.find_healthchecks', return_value=(checks, '')):138 self.tested_fn._run(self.deployment)139 self.deployment.consul_api.register_script_check.assert_called_once_with('my-mock-service', 'my-mock-service:test_check', 'test-script', 'test-script.py', '10')140 @patch('os.stat')141 @patch('os.chmod')142 @patch('os.path.exists', return_value=True)143 def test_script_check_registration_with_slice(self, stat, chmod, exists):144 checks = {145 'test_check': self.create_check(True, 'test-script', 'test-script.py', '10')146 }147 self.deployment.set_checks(checks)148 self.deployment.service.set_slice('blue')149 self.deployment.consul_api = MagicMock()150 with patch('agent.deployment_stages.consul_healthchecks.find_healthchecks', return_value=(checks, '')):151 self.tested_fn._run(self.deployment)152 self.deployment.consul_api.register_script_check.assert_called_once_with('my-mock-service', 'my-mock-service:test_check', 'test-script', 'test-script.py blue', '10')153 @patch('os.stat')154 @patch('os.chmod')155 @patch('os.path.exists', return_value=True)156 def test_windows_script_check_registration(self, stat, chmod, exists):157 checks = {158 'test_check': self.create_check(True, 'test-script', 'test-script.ps1', '10')159 }160 self.deployment.set_checks(checks)161 self.deployment.consul_api = MagicMock()162 self.deployment.set_platform('windows')163 with patch('agent.deployment_stages.consul_healthchecks.find_healthchecks', return_value=(checks, '')):164 self.tested_fn._run(self.deployment)165 self.deployment.consul_api.register_script_check.assert_called_once_with('my-mock-service', 'my-mock-service:test_check', 'test-script', 'powershell.exe -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned -Command "test-script.ps1"', '10')166 @patch('os.stat')167 @patch('os.chmod')168 @patch('os.path.exists', return_value=True)169 def test_windows_script_check_registration_with_slice(self, stat, chmod, exists):170 checks = {171 'test_check': self.create_check(True, 'test-script', 'test-script.ps1', '10')172 }173 self.deployment.set_checks(checks)174 self.deployment.service.set_slice('blue')175 self.deployment.consul_api = MagicMock()176 self.deployment.set_platform('windows')177 with patch('agent.deployment_stages.consul_healthchecks.find_healthchecks', return_value=(checks, '')):178 self.tested_fn._run(self.deployment)179 self.deployment.consul_api.register_script_check.assert_called_once_with('my-mock-service', 'my-mock-service:test_check', 'test-script', 'powershell.exe -NonInteractive -NoProfile -ExecutionPolicy RemoteSigned -Command "test-script.ps1 blue"', '10')180 @patch('os.stat')181 @patch('os.chmod')182 @patch('os.path.exists', return_value=True)183 def test_script_http_registration(self, stat, chmod, exists):184 checks = {185 'test_http_check': self.create_check(False, 'test-http', 'http://acme.com/healthcheck', '20', False)186 }187 self.deployment.set_checks(checks)188 self.deployment.consul_api = MagicMock()189 with patch('agent.deployment_stages.consul_healthchecks.find_healthchecks', return_value=(checks, '')):190 self.tested_fn._run(self.deployment)191 self.deployment.consul_api.register_http_check.assert_called_once_with('my-mock-service', 'my-mock-service:test_http_check', 'test-http', 'http://acme.com/healthcheck', '20', False)192 @patch('os.stat')193 @patch('os.chmod')194 @patch('os.path.exists', return_value=True)195 def test_script_http_registration_with_tls_skip_verify(self, stat, chmod, exists):196 checks = {197 'test_http_check': self.create_check(False, 'test-http', 'http://acme.com/healthcheck', '20', True)198 }199 self.deployment.set_checks(checks)200 self.deployment.consul_api = MagicMock()201 with patch('agent.deployment_stages.consul_healthchecks.find_healthchecks', return_value=(checks, '')):202 self.tested_fn._run(self.deployment)203 self.deployment.consul_api.register_http_check.assert_called_once_with('my-mock-service', 'my-mock-service:test_http_check', 'test-http', 'http://acme.com/healthcheck', '20', True)204 205 @patch('os.stat')206 @patch('os.chmod')207 @patch('os.path.exists', return_value=True)208 def test_script_http_registration_with_port(self, stat, chmod, exists):209 checks = {210 'test_http_check': self.create_check(False, 'test-http', 'http://localhost:${PORT}/service/api', '20')211 }212 self.deployment.set_checks(checks)213 self.deployment.consul_api = MagicMock()214 with patch('agent.deployment_stages.consul_healthchecks.find_healthchecks', return_value=(checks, '')):215 self.tested_fn._run(self.deployment)216 expected_url = 'http://localhost:{0}/service/api'.format(MOCK_PORT)217 self.deployment.consul_api.register_http_check.assert_called_once_with('my-mock-service', 'my-mock-service:test_http_check', 'test-http', expected_url, '20', False)218 219 @patch('os.stat') 220 @patch('os.chmod')221 @patch('os.path.exists', return_value=True)222 def test_http_check_registration_with_slice(self, stat, chmod, exists):223 checks = {224 'test_http_check': self.create_check(False, 'test-http', 'http://acme.com/healthcheck', '20')225 }226 self.deployment.set_checks(checks)227 self.deployment.service.set_slice('blue')228 self.deployment.consul_api = MagicMock()229 # Slice value should not affect http value230 with patch('agent.deployment_stages.consul_healthchecks.find_healthchecks', return_value=(checks, '')):231 self.tested_fn._run(self.deployment)232 self.deployment.consul_api.register_http_check.assert_called_once_with('my-mock-service', 'my-mock-service:test_http_check', 'test-http', 'http://acme.com/healthcheck', '20', False)233 234 def create_check(self, is_script, name, value, interval, tls_skip_verify=False):235 check = { 'name':name, 'interval':interval }236 if is_script:237 check['type'] = 'script'238 check['script'] = value239 else:240 check['type'] = 'http'...

Full Screen

Full Screen

consul_health_check_test.py

Source:consul_health_check_test.py Github

copy

Full Screen

...28 }29 self.service = {30 id: 'my-mock-service'31 }32def set_checks(sut, checks):33 sut.appspec = {34 'consul_healthchecks': checks35 }36def set_check(sut, check_id, check):37 sut.appspec = {38 'consul_healthchecks': {39 check_id: check40 }41 }42class TestHealthChecks(unittest.TestCase):43 def setUp(self):44 self.deployment = MockDeployment()45 self.logger = MockLogger()46 self.archive_dir = ''47 self.appspec = {48 'healthchecks': HEALTHCHECKS49 }50 self.service_id = 'my-mock-service'51 self.tested_fn = ConsulHealthCheck(52 name="ConsulHealthCheck",53 logger=self.logger,54 archive_dir=self.archive_dir,55 appspec=self.appspec,56 service_id=self.service_id,57 api=MagicMock()58 )59 def test_failing_check(self):60 check = {61 'type': 'unknown',62 'name': 'check_name'63 }64 set_check(self.tested_fn, 'check_failing', check)65 with self.assertRaisesRegexp(RegisterError, 'only.*check types are supported'):66 self.tested_fn.register()67 def test_missing_name_field(self):68 check = {69 'type': 'http',70 'name': 'check_name'71 }72 set_check(self.tested_fn, 'check_failing', check)73 with self.assertRaisesRegexp(RegisterError, 'is missing field'):74 self.tested_fn.register()75 def test_missing_http_field(self):76 check = {77 'type': 'http',78 'name': 'Missing http'79 }80 set_check(self.tested_fn, 'check_failing', check)81 with self.assertRaisesRegexp(RegisterError, 'is missing field \'http\''):82 self.tested_fn.register()83 def test_case_insensitive_id_conflict(self):84 checks = {85 'check_1': {86 'type': 'http',87 'name': 'Missing http 1'88 },89 'cheCK_1': {90 'type': 'http',91 'name': 'Missing http 2'92 }93 }94 set_checks(self.tested_fn, checks)95 with self.assertRaisesRegexp(RegisterError, 'health checks require unique ids'):96 self.tested_fn.register()97 def test_case_insensitive_name_conflict(self):98 checks = {99 'check_1': {100 'type': 'http',101 'name': 'Missing http'102 },103 'check_2': {104 'type': 'http',105 'name': 'Missing http'106 }107 }108 set_checks(self.tested_fn, checks)109 with self.assertRaisesRegexp(RegisterError, 'health checks require unique names'):110 self.tested_fn.register()111 @patch('os.stat')112 @patch('os.chmod')113 @patch('os.path.exists', return_value=True)114 def test_script_check_registration(self, stat, chmod, exists):115 checks = {116 'test_check': self.create_check(True, 'test-script', 'test-script.py', '10')117 }118 set_checks(self.tested_fn, checks)119 self.api = MagicMock()120 with patch.object(ConsulHealthCheck, 'find_health_checks') as mock_health_check:121 mock_health_check.return_value = (checks, '')122 self.tested_fn.register()123 self.tested_fn.api.register_script_check.assert_called_once_with(124 'my-mock-service', 'my-mock-service:test_check', 'test-script', 'test-script.py', '10')125 @patch('os.stat')126 @patch('os.chmod')127 @patch('os.path.exists', return_value=True)128 def test_script_check_registration_with_slice(self, stat, chmod, exists):129 checks = {130 'test_check': self.create_check(True, 'test-script', 'test-script.py', '10')131 }132 set_checks(self.tested_fn, checks)133 set_slice(self.tested_fn, 'blue')134 self.tested_fn.api = MagicMock()135 with patch.object(ConsulHealthCheck, 'find_health_checks') as mock_health_check:136 mock_health_check.return_value = (checks, '')137 self.tested_fn.register()138 self.tested_fn.api.register_script_check.assert_called_once_with(139 'my-mock-service', 'my-mock-service:test_check', 'test-script', 'test-script.py blue', '10')140 @patch('os.stat')141 @patch('os.chmod')142 @patch('os.path.exists', return_value=True)143 def test_script_http_registration(self, stat, chmod, exists):144 checks = {145 'test_http_check': self.create_check(False, 'test-http', 'http://acme.com/healthcheck', '20')146 }147 set_checks(self.tested_fn, checks)148 with patch.object(ConsulHealthCheck, 'find_health_checks') as mock_health_check:149 mock_health_check.return_value = (checks, '')150 self.tested_fn.register()151 self.tested_fn.api.register_http_check.assert_called_once_with(152 'my-mock-service', 'my-mock-service:test_http_check', 'test-http', 'http://acme.com/healthcheck', '20')153 @patch('os.stat')154 @patch('os.chmod')155 @patch('os.path.exists', return_value=True)156 def test_http_check_registration_with_slice(self, stat, chmod, exists):157 checks = {158 'test_http_check': self.create_check(False, 'test-http', 'http://acme.com/healthcheck', '20')159 }160 set_checks(self.tested_fn, checks)161 set_slice(self.tested_fn, 'blue')162 # Slice value should not affect http value163 with patch.object(ConsulHealthCheck, 'find_health_checks') as mock_health_check:164 mock_health_check.return_value = (checks, '')165 self.tested_fn.register()166 self.tested_fn.api.register_http_check.assert_called_once_with(167 'my-mock-service', 'my-mock-service:test_http_check', 'test-http', 'http://acme.com/healthcheck', '20')168 def create_check(self, is_script, name, value, interval):169 check = {'name': name, 'interval': interval}170 if is_script:171 check['type'] = 'script'172 check['script'] = value173 else:174 check['type'] = 'http'...

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