How to use discard_namespace method in autotest

Best Python code snippet using autotest_python

base_job_unittest.py

Source:base_job_unittest.py Github

copy

Full Screen

...341 self.assert_(not self.state.has('ns18_2', 'name26'))342 def test_discard_namespace_drops_all_values(self):343 self.state.set('ns19', 'var1', 10)344 self.state.set('ns19', 'var3', 100)345 self.state.discard_namespace('ns19')346 self.assertRaises(KeyError, self.state.get, 'ns19', 'var1')347 self.assertRaises(KeyError, self.state.get, 'ns19', 'var3')348 def test_discard_namespace_works_on_missing_namespace(self):349 self.state.discard_namespace('missing_ns')350 def test_discard_namespace_doesnt_touch_other_values(self):351 self.state.set('ns20', 'var1', 20)352 self.state.set('ns20', 'var2', 200)353 self.state.set('ns21', 'var2', 21)354 self.state.discard_namespace('ns20')355 self.assertEqual(21, self.state.get('ns21', 'var2'))356# run the same tests as test_job_state, but with a backing file turned on357# also adds some tests to check that each method is persistent358class test_job_state_with_backing_file(test_job_state):359 def setUp(self):360 self.backing_file = tempfile.mktemp()361 self.state = base_job.job_state()362 self.state.set_backing_file(self.backing_file)363 def tearDown(self):364 if os.path.exists(self.backing_file):365 os.remove(self.backing_file)366 def test_set_is_persistent(self):367 self.state.set('persist', 'var', 'value')368 written_state = base_job.job_state()369 written_state.read_from_file(self.backing_file)370 self.assertEqual('value', written_state.get('persist', 'var'))371 def test_discard_is_persistent(self):372 self.state.set('persist', 'var', 'value')373 self.state.discard('persist', 'var')374 written_state = base_job.job_state()375 written_state.read_from_file(self.backing_file)376 self.assertRaises(KeyError, written_state.get, 'persist', 'var')377 def test_discard_namespace_is_persistent(self):378 self.state.set('persist', 'var', 'value')379 self.state.discard_namespace('persist')380 written_state = base_job.job_state()381 written_state.read_from_file(self.backing_file)382 self.assertRaises(KeyError, written_state.get, 'persist', 'var')383class test_job_state_read_write_file(unittest.TestCase):384 def setUp(self):385 self.testdir = tempfile.mkdtemp(suffix='unittest')386 self.original_wd = os.getcwd()387 os.chdir(self.testdir)388 def tearDown(self):389 os.chdir(self.original_wd)390 shutil.rmtree(self.testdir, ignore_errors=True)391 def test_write_read_transfers_all_state(self):392 state1 = base_job.job_state()393 state1.set('ns1', 'var0', 50)394 state1.set('ns2', 'var10', 100)395 state1.write_to_file('transfer_file')396 state2 = base_job.job_state()397 self.assertRaises(KeyError, state2.get, 'ns1', 'var0')398 self.assertRaises(KeyError, state2.get, 'ns2', 'var10')399 state2.read_from_file('transfer_file')400 self.assertEqual(50, state2.get('ns1', 'var0'))401 self.assertEqual(100, state2.get('ns2', 'var10'))402 def test_read_overwrites_in_memory(self):403 state = base_job.job_state()404 state.set('ns', 'myvar', 'hello')405 state.write_to_file('backup')406 state.set('ns', 'myvar', 'goodbye')407 self.assertEqual('goodbye', state.get('ns', 'myvar'))408 state.read_from_file('backup')409 self.assertEqual('hello', state.get('ns', 'myvar'))410 def test_read_updates_persistent_file(self):411 state1 = base_job.job_state()412 state1.set('ns', 'var1', 'value1')413 state1.write_to_file('to_be_read')414 state2 = base_job.job_state()415 state2.set_backing_file('backing_file')416 state2.set('ns', 'var2', 'value2')417 state2.read_from_file('to_be_read')418 state2.set_backing_file(None)419 state3 = base_job.job_state()420 state3.read_from_file('backing_file')421 self.assertEqual('value1', state3.get('ns', 'var1'))422 self.assertEqual('value2', state3.get('ns', 'var2'))423 def test_read_without_merge(self):424 state = base_job.job_state()425 state.set('ns', 'myvar1', 'hello')426 state.write_to_file('backup')427 state.discard('ns', 'myvar1')428 state.set('ns', 'myvar2', 'goodbye')429 self.assertFalse(state.has('ns', 'myvar1'))430 self.assertEqual('goodbye', state.get('ns', 'myvar2'))431 state.read_from_file('backup', merge=False)432 self.assertEqual('hello', state.get('ns', 'myvar1'))433 self.assertFalse(state.has('ns', 'myvar2'))434class test_job_state_set_backing_file(unittest.TestCase):435 def setUp(self):436 self.testdir = tempfile.mkdtemp(suffix='unittest')437 self.original_wd = os.getcwd()438 os.chdir(self.testdir)439 def tearDown(self):440 os.chdir(self.original_wd)441 shutil.rmtree(self.testdir, ignore_errors=True)442 def test_writes_to_file(self):443 state = base_job.job_state()444 state.set_backing_file('outfile1')445 self.assert_(os.path.exists('outfile1'))446 def test_set_backing_file_updates_existing_file(self):447 state1 = base_job.job_state()448 state1.set_backing_file('second_file')449 state1.set('ns0', 'var1x', 100)450 state1.set_backing_file(None)451 state2 = base_job.job_state()452 state2.set_backing_file('first_file')453 state2.set('ns0', 'var0x', 0)454 state2.set_backing_file('second_file')455 state2.set_backing_file(None)456 state3 = base_job.job_state()457 state3.read_from_file('second_file')458 self.assertEqual(0, state3.get('ns0', 'var0x'))459 self.assertEqual(100, state3.get('ns0', 'var1x'))460 def test_set_backing_file_does_not_overwrite_previous_backing_file(self):461 state1 = base_job.job_state()462 state1.set_backing_file('second_file')463 state1.set('ns0', 'var1y', 10)464 state1.set_backing_file(None)465 state2 = base_job.job_state()466 state2.set_backing_file('first_file')467 state2.set('ns0', 'var0y', -10)468 state2.set_backing_file('second_file')469 state2.set_backing_file(None)470 state3 = base_job.job_state()471 state3.read_from_file('first_file')472 self.assertEqual(-10, state3.get('ns0', 'var0y'))473 self.assertRaises(KeyError, state3.get, 'ns0', 'var1y')474 def test_writes_stop_after_backing_file_removed(self):475 state = base_job.job_state()476 state.set('ns', 'var1', 'value1')477 state.set_backing_file('outfile2')478 state.set_backing_file(None)479 os.remove('outfile2')480 state.set('n2', 'var2', 'value2')481 self.assert_(not os.path.exists('outfile2'))482 def test_written_files_can_be_reloaded(self):483 state1 = base_job.job_state()484 state1.set_backing_file('outfile3')485 state1.set('n3', 'var1', 67)486 state1.set_backing_file(None)487 state2 = base_job.job_state()488 self.assertRaises(KeyError, state2.get, 'n3', 'var1')489 state2.set_backing_file('outfile3')490 self.assertEqual(67, state2.get('n3', 'var1'))491 def test_backing_file_overrides_in_memory_values(self):492 state1 = base_job.job_state()493 state1.set_backing_file('outfile4')494 state1.set('n4', 'var1', 42)495 state1.set_backing_file(None)496 state2 = base_job.job_state()497 state2.set('n4', 'var1', 430)498 self.assertEqual(430, state2.get('n4', 'var1'))499 state2.set_backing_file('outfile4')500 self.assertEqual(42, state2.get('n4', 'var1'))501 def test_backing_file_only_overrides_values_it_defines(self):502 state1 = base_job.job_state()503 state1.set_backing_file('outfile5')504 state1.set('n5', 'var1', 123)505 state1.set_backing_file(None)506 state2 = base_job.job_state()507 state2.set('n5', 'var2', 456)508 state2.set_backing_file('outfile5')509 self.assertEqual(123, state2.get('n5', 'var1'))510 self.assertEqual(456, state2.get('n5', 'var2'))511 def test_shared_backing_file_propagates_state_to_get(self):512 state1 = base_job.job_state()513 state1.set_backing_file('outfile6')514 state2 = base_job.job_state()515 state2.set_backing_file('outfile6')516 self.assertRaises(KeyError, state1.get, 'n6', 'shared1')517 self.assertRaises(KeyError, state2.get, 'n6', 'shared1')518 state1.set('n6', 'shared1', 345)519 self.assertEqual(345, state1.get('n6', 'shared1'))520 self.assertEqual(345, state2.get('n6', 'shared1'))521 def test_shared_backing_file_propagates_state_to_has(self):522 state1 = base_job.job_state()523 state1.set_backing_file('outfile7')524 state2 = base_job.job_state()525 state2.set_backing_file('outfile7')526 self.assertFalse(state1.has('n6', 'shared2'))527 self.assertFalse(state2.has('n6', 'shared2'))528 state1.set('n6', 'shared2', 'hello')529 self.assertTrue(state1.has('n6', 'shared2'))530 self.assertTrue(state2.has('n6', 'shared2'))531 def test_shared_backing_file_propagates_state_from_discard(self):532 state1 = base_job.job_state()533 state1.set_backing_file('outfile8')534 state1.set('n6', 'shared3', 10000)535 state2 = base_job.job_state()536 state2.set_backing_file('outfile8')537 self.assertEqual(10000, state1.get('n6', 'shared3'))538 self.assertEqual(10000, state2.get('n6', 'shared3'))539 state1.discard('n6', 'shared3')540 self.assertRaises(KeyError, state1.get, 'n6', 'shared3')541 self.assertRaises(KeyError, state2.get, 'n6', 'shared3')542 def test_shared_backing_file_propagates_state_from_discard_namespace(self):543 state1 = base_job.job_state()544 state1.set_backing_file('outfile9')545 state1.set('n7', 'shared4', -1)546 state1.set('n7', 'shared5', -2)547 state2 = base_job.job_state()548 state2.set_backing_file('outfile9')549 self.assertEqual(-1, state1.get('n7', 'shared4'))550 self.assertEqual(-1, state2.get('n7', 'shared4'))551 self.assertEqual(-2, state1.get('n7', 'shared5'))552 self.assertEqual(-2, state2.get('n7', 'shared5'))553 state1.discard_namespace('n7')554 self.assertRaises(KeyError, state1.get, 'n7', 'shared4')555 self.assertRaises(KeyError, state2.get, 'n7', 'shared4')556 self.assertRaises(KeyError, state1.get, 'n7', 'shared5')557 self.assertRaises(KeyError, state2.get, 'n7', 'shared5')558class test_job_state_backing_file_locking(unittest.TestCase):559 def setUp(self):560 self.testdir = tempfile.mkdtemp(suffix='unittest')561 self.original_wd = os.getcwd()562 os.chdir(self.testdir)563 # create a job_state object with stub read_* and write_* methods564 # to check that a lock is always held during a call to them565 ut_self = self566 class mocked_job_state(base_job.job_state):567 def read_from_file(self, file_path, merge=True):568 if self._backing_file and file_path == self._backing_file:569 ut_self.assertNotEqual(None, self._backing_file_lock)570 return super(mocked_job_state, self).read_from_file(571 file_path, merge=True)572 def write_to_file(self, file_path):573 if self._backing_file and file_path == self._backing_file:574 ut_self.assertNotEqual(None, self._backing_file_lock)575 return super(mocked_job_state, self).write_to_file(file_path)576 self.state = mocked_job_state()577 self.state.set_backing_file('backing_file')578 def tearDown(self):579 os.chdir(self.original_wd)580 shutil.rmtree(self.testdir, ignore_errors=True)581 def test_set(self):582 self.state.set('ns1', 'var1', 100)583 def test_get_missing(self):584 self.assertRaises(KeyError, self.state.get, 'ns2', 'var2')585 def test_get_present(self):586 self.state.set('ns3', 'var3', 333)587 self.assertEqual(333, self.state.get('ns3', 'var3'))588 def test_set_backing_file(self):589 self.state.set_backing_file('some_other_file')590 def test_has_missing(self):591 self.assertFalse(self.state.has('ns4', 'var4'))592 def test_has_present(self):593 self.state.set('ns5', 'var5', 55555)594 self.assertTrue(self.state.has('ns5', 'var5'))595 def test_discard_missing(self):596 self.state.discard('ns6', 'var6')597 def test_discard_present(self):598 self.state.set('ns7', 'var7', -777)599 self.state.discard('ns7', 'var7')600 def test_discard_missing_namespace(self):601 self.state.discard_namespace('ns8')602 def test_discard_present_namespace(self):603 self.state.set('ns8', 'var8', 80)604 self.state.set('ns8', 'var8.1', 81)605 self.state.discard_namespace('ns8')606 def test_disable_backing_file(self):607 self.state.set_backing_file(None)608 def test_change_backing_file(self):609 self.state.set_backing_file('another_backing_file')610 def test_read_from_a_non_backing_file(self):611 state = base_job.job_state()612 state.set('ns9', 'var9', 9999)613 state.write_to_file('non_backing_file')614 self.state.read_from_file('non_backing_file')615 def test_write_to_a_non_backing_file(self):616 self.state.write_to_file('non_backing_file')617class test_job_state_property_factory(unittest.TestCase):618 def setUp(self):619 class job_stub(object):...

Full Screen

Full Screen

searcher.py

Source:searcher.py Github

copy

Full Screen

...102 # Left join - leaves pages with no translation in, but sets None in target language column103 result = matches.join(df).drop(columns=0)104 result.columns = [f'title_{lang_from}', f'title_{lang_to}']105 return result106def discard_namespace(row):107 """108 Removes namespace (like Category: from page title). Based around position of colon (:) in the translated title.109 Namespaces are not present in titles from the `pages` table, but are present in `langlinks`.110 Therefore, a namespaced page translation should have more colons than the original title.111 If that is the case, anything before the first colon in the translated title is discarded.112 :param row: A row of pd.Dataframe with original title [0] and translated title [1]113 :return: Modified row114 """115 if row.iloc[1].count(':') > row.iloc[0].count(':'):116 colon = row.iloc[1].find(':')117 if colon:118 row.iloc[1] = row.iloc[1][colon + 1:]119 return row120if __name__ == '__main__':...

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