How to use eval method in fMBT

Best Python code snippet using fMBT_python

experiment_test.py

Source:experiment_test.py Github

copy

Full Screen

...344 with test.mock.patch.object(time, 'sleep', sheep.sleep):345 ex.evaluate(delay_secs=delay)346 self.assertAlmostEqual(delay, sheep.time(), delta=1e-4)347 self.assertEqual([noop_hook], est.eval_hooks)348 def test_continuous_eval(self):349 for est in self._estimators_for_tests(eval_dict={'global_step': 100}):350 eval_metrics = 'eval_metrics' if not isinstance(351 est, core_estimator.Estimator) else None352 est.fake_checkpoint()353 noop_hook = _NoopHook()354 ex = experiment.Experiment(355 est,356 train_input_fn='train_input',357 eval_input_fn='eval_input',358 eval_metrics=eval_metrics,359 eval_hooks=[noop_hook],360 eval_delay_secs=0,361 continuous_eval_throttle_secs=0)362 self.assertRaises(StopIteration, ex.continuous_eval,363 evaluate_checkpoint_only_once=False)364 self.assertEqual(0, est.fit_count)365 self.assertEqual(6, est.eval_count)366 self.assertEqual([noop_hook], est.eval_hooks)367 def test_continuous_eval_ends_after_train_step(self):368 for est in self._estimators_for_tests(eval_dict={'global_step': 100}):369 eval_metrics = 'eval_metrics' if not isinstance(370 est, core_estimator.Estimator) else None371 est.fake_checkpoint()372 noop_hook = _NoopHook()373 ex = experiment.Experiment(374 est,375 train_input_fn='train_input',376 eval_input_fn='eval_input',377 eval_metrics=eval_metrics,378 eval_hooks=[noop_hook],379 eval_delay_secs=0,380 continuous_eval_throttle_secs=0,381 train_steps=100)382 ex.continuous_eval()383 self.assertEqual(0, est.fit_count)384 self.assertEqual(1, est.eval_count)385 self.assertEqual([noop_hook], est.eval_hooks)386 def test_continuous_eval_throttle_delay(self):387 for delay in [0, 1, 2]:388 for est in self._estimators_for_tests():389 eval_metrics = 'eval_metrics' if not isinstance(390 est, core_estimator.Estimator) else None391 est.fake_checkpoint()392 noop_hook = _NoopHook()393 ex = experiment.Experiment(394 est,395 train_input_fn='train_input',396 eval_input_fn='eval_input',397 eval_metrics=eval_metrics,398 eval_hooks=[noop_hook],399 continuous_eval_throttle_secs=delay,400 eval_delay_secs=0)401 sheep = SheepCounter()402 with test.mock.patch.object(time, 'time', sheep.time):403 with test.mock.patch.object(time, 'sleep', sheep.sleep):404 self.assertRaises(405 StopIteration,406 ex.continuous_eval,407 evaluate_checkpoint_only_once=False)408 self.assertAlmostEqual(5 * delay, sheep.time(), delta=1e-4)409 def test_continuous_eval_predicate_fn(self):410 for est in self._estimators_for_tests():411 eval_metrics = 'eval_metrics' if not isinstance(412 est, core_estimator.Estimator) else None413 est.fake_checkpoint()414 noop_hook = _NoopHook()415 def _predicate_fn(unused_eval_result):416 return est.eval_count < 3 # pylint: disable=cell-var-from-loop417 ex = experiment.Experiment(418 est,419 train_input_fn='train_input',420 eval_input_fn='eval_input',421 eval_metrics=eval_metrics,422 eval_hooks=[noop_hook],423 eval_delay_secs=0,424 continuous_eval_throttle_secs=0)425 ex.continuous_eval(evaluate_checkpoint_only_once=False,426 continuous_eval_predicate_fn=_predicate_fn)427 self.assertEqual(0, est.fit_count)428 self.assertEqual(3, est.eval_count)429 self.assertEqual([noop_hook], est.eval_hooks)430 def test_continuous_eval_predicate_fn_with_checkpoint(self):431 for est in self._estimators_for_tests():432 eval_metrics = 'eval_metrics' if not isinstance(433 est, core_estimator.Estimator) else None434 est.fake_checkpoint()435 noop_hook = _NoopHook()436 def _predicate_fn(eval_result, checkpoint_path):437 self.assertEqual(eval_result is None,438 checkpoint_path is None)439 return est.eval_count < 3 # pylint: disable=cell-var-from-loop440 ex = experiment.Experiment(441 est,442 train_input_fn='train_input',443 eval_input_fn='eval_input',444 eval_metrics=eval_metrics,445 eval_hooks=[noop_hook],446 eval_delay_secs=0,447 continuous_eval_throttle_secs=0)448 ex.continuous_eval(449 evaluate_checkpoint_only_once=False,450 continuous_eval_predicate_fn=_predicate_fn)451 self.assertEqual(0, est.fit_count)452 self.assertEqual(3, est.eval_count)453 self.assertEqual([noop_hook], est.eval_hooks)454 def test_run_local(self):455 for est in self._estimators_for_tests():456 eval_metrics = 'eval_metrics' if not isinstance(457 est, core_estimator.Estimator) else None458 noop_hook = _NoopHook()459 ex = experiment.Experiment(460 est,461 train_input_fn='train_input',462 eval_input_fn='eval_input',463 eval_metrics=eval_metrics,464 eval_hooks=[noop_hook],465 train_steps=100,466 eval_steps=100,467 local_eval_frequency=10)468 ex.local_run()469 self.assertEqual(1, est.fit_count)470 self.assertEqual(1, est.eval_count)471 self.assertEqual(1, len(est.monitors))472 self.assertEqual([noop_hook], est.eval_hooks)473 self.assertTrue(isinstance(est.monitors[0],474 session_run_hook.SessionRunHook))475 def test_train_hooks_extend_does_not_mutate_input_hooks(self):476 for est in self._estimators_for_tests():477 eval_metrics = 'eval_metrics' if not isinstance(478 est, core_estimator.Estimator) else None479 noop_hook = _NoopHook()480 input_hooks = [noop_hook]481 ex = experiment.Experiment(482 est,483 train_input_fn='train_input',484 eval_input_fn='eval_input',485 eval_metrics=eval_metrics,486 train_monitors=input_hooks)487 self.assertAllEqual([noop_hook], ex._train_monitors)488 another_noop_hook = _NoopHook()489 # Assert that the extend API mutates the hooks, but not the input hooks490 ex.extend_train_hooks([another_noop_hook])491 self.assertAllEqual([noop_hook, another_noop_hook], ex._train_monitors)492 self.assertAllEqual([noop_hook], input_hooks)493 def test_invalid_export_strategies(self):494 for est in self._estimators_for_tests():495 with self.assertRaisesRegexp(ValueError, 'ExportStrategy'):496 experiment.Experiment(497 est,498 train_input_fn='train_input',499 eval_input_fn='eval_input',500 train_steps=100,501 eval_steps=100,502 export_strategies='not_an_export_strategy')503 with self.assertRaisesRegexp(ValueError, 'ExportStrategy'):504 experiment.Experiment(505 est,506 train_input_fn='train_input',507 eval_input_fn='eval_input',508 train_steps=100,509 eval_steps=100,510 export_strategies=['not_an_export_srategy'])511 def test_export_strategies_reset(self):512 for est in self._estimators_for_tests():513 eval_metrics = 'eval_metrics' if not isinstance(514 est, core_estimator.Estimator) else None515 export_strategy_1 = saved_model_export_utils.make_export_strategy(516 est,517 None if isinstance(est, core_estimator.Estimator) else 'export_1',518 exports_to_keep=None)519 ex = experiment.Experiment(520 est,521 train_input_fn='train_input',522 eval_input_fn='eval_input',523 eval_metrics=eval_metrics,524 train_steps=100,525 eval_steps=100,526 export_strategies=(export_strategy_1,))527 ex.train_and_evaluate()528 self.assertEqual(1, est.export_count)529 # After reset with empty list (None), the count does not change and the530 # user provided export strategy list should remain intact.531 old_es = ex.reset_export_strategies()532 ex.train_and_evaluate()533 self.assertAllEqual([export_strategy_1], old_es)534 self.assertEqual(1, est.export_count)535 # After reset with list, the count should increase with the number of536 # items.537 export_strategy_2 = saved_model_export_utils.make_export_strategy(538 est,539 None if isinstance(est, core_estimator.Estimator) else 'export_2',540 exports_to_keep=None)541 export_strategy_3 = saved_model_export_utils.make_export_strategy(542 est,543 None if isinstance(est, core_estimator.Estimator) else 'export_3',544 exports_to_keep=None)545 old_es = ex.reset_export_strategies(546 [export_strategy_2, export_strategy_3])547 ex.train_and_evaluate()548 self.assertAllEqual([], old_es)549 self.assertEqual(3, est.export_count)550 def test_train_and_evaluate(self):551 for est in self._estimators_for_tests():552 eval_metrics = 'eval_metrics' if not isinstance(553 est, core_estimator.Estimator) else None554 noop_hook = _NoopHook()555 export_strategy = saved_model_export_utils.make_export_strategy(556 est,557 None if isinstance(est, core_estimator.Estimator) else 'export_input',558 exports_to_keep=None)559 ex = experiment.Experiment(560 est,561 train_input_fn='train_input',562 eval_input_fn='eval_input',563 eval_metrics=eval_metrics,564 eval_hooks=[noop_hook],565 train_steps=100,566 eval_steps=100,567 export_strategies=export_strategy)568 ex.train_and_evaluate()569 self.assertEqual(1, est.fit_count)570 self.assertEqual(1, est.eval_count)571 self.assertEqual(1, est.export_count)572 self.assertEqual(1, len(est.monitors))573 self.assertEqual([noop_hook], est.eval_hooks)574 self.assertTrue(isinstance(est.monitors[0],575 session_run_hook.SessionRunHook))576 def test_train_and_evaluate_with_no_eval_during_training(self):577 for est in self._estimators_for_tests():578 eval_metrics = 'eval_metrics' if not isinstance(579 est, core_estimator.Estimator) else None580 noop_hook = _NoopHook()581 ex = experiment.Experiment(582 est,583 train_input_fn='train_input',584 eval_input_fn='eval_input',585 eval_metrics=eval_metrics,586 eval_hooks=[noop_hook],587 train_steps=100,588 eval_steps=100,589 min_eval_frequency=0)590 ex.train_and_evaluate()591 self.assertEqual(1, est.fit_count)592 self.assertEqual(1, est.eval_count)593 self.assertEqual(0, len(est.monitors))594 def test_min_eval_frequency_defaults(self):595 def dummy_model_fn(features, labels): # pylint: disable=unused-argument596 pass597 estimator = core_estimator.Estimator(dummy_model_fn, '/tmp/dummy')598 ex = experiment.Experiment(599 estimator, train_input_fn=None, eval_input_fn=None)600 self.assertEquals(ex._min_eval_frequency, 1)601 def test_continuous_train_and_eval(self):602 for est in self._estimators_for_tests(eval_dict={'global_step': 100}):603 if isinstance(est, core_estimator.Estimator):604 eval_metrics = None605 saving_listeners = 'saving_listeners'606 else:607 eval_metrics = 'eval_metrics'608 saving_listeners = None609 noop_hook = _NoopHook()610 export_strategy = saved_model_export_utils.make_export_strategy(611 est,612 None if isinstance(est, core_estimator.Estimator) else 'export_input',613 exports_to_keep=None)614 ex = experiment.Experiment(615 est,616 train_input_fn='train_input',617 eval_input_fn='eval_input',618 eval_metrics=eval_metrics,619 eval_hooks=[noop_hook],620 train_steps=100,621 eval_steps=100,622 export_strategies=export_strategy,623 saving_listeners=saving_listeners)624 ex.continuous_train_and_eval()625 self.assertEqual(1, est.fit_count)626 self.assertEqual(1, est.eval_count)627 self.assertEqual(1, est.export_count)628 self.assertEqual([noop_hook], est.eval_hooks)629 def test_continuous_train_and_eval_with_predicate_fn(self):630 for est in self._estimators_for_tests(eval_dict={'global_step': 100}):631 eval_metrics = 'eval_metrics' if not isinstance(632 est, core_estimator.Estimator) else None633 export_strategy = saved_model_export_utils.make_export_strategy(634 est,635 None if isinstance(est, core_estimator.Estimator) else 'export_input',636 exports_to_keep=None)637 ex = experiment.Experiment(638 est,639 train_input_fn='train_input',640 eval_input_fn='eval_input',641 eval_metrics=eval_metrics,642 train_steps=100000000000, # a value will make `ex` never stops.643 eval_steps=100,644 export_strategies=export_strategy)645 def predicate_fn(eval_result):646 del eval_result # unused. for fn signature.647 return False648 ex.continuous_train_and_eval(continuous_eval_predicate_fn=predicate_fn)649 self.assertEqual(0, est.fit_count)650 self.assertEqual(0, est.eval_count)651 self.assertEqual(0, est.export_count)652 def test_continuous_train_and_eval_with_adapted_steps_per_iteration(self):653 mock_estimator = test.mock.Mock(core_estimator.Estimator)654 type(mock_estimator).model_dir = test.mock.PropertyMock(655 return_value='test_dir')656 total_steps = 100000000000000657 ex = experiment.Experiment(658 mock_estimator,659 train_input_fn='train_input',660 eval_input_fn='eval_input',661 train_steps=total_steps)662 def predicate_fn(eval_result):663 # Allows the first invoke only.664 return eval_result is None665 ex.continuous_train_and_eval(continuous_eval_predicate_fn=predicate_fn)666 mock_estimator.train.assert_called_once_with(667 input_fn='train_input',668 steps=int(total_steps / 10),669 max_steps=test.mock.ANY,670 hooks=test.mock.ANY,671 saving_listeners=test.mock.ANY)672 def test_continuous_train_and_eval_with_steps_per_iteration_from_user(self):673 mock_estimator = test.mock.Mock(core_estimator.Estimator)674 type(mock_estimator).model_dir = test.mock.PropertyMock(675 return_value='test_dir')676 total_steps = 100000000000000677 ex = experiment.Experiment(678 mock_estimator,679 train_input_fn='train_input',680 eval_input_fn='eval_input',681 train_steps_per_iteration=1234,682 train_steps=total_steps)683 def predicate_fn(eval_result):684 # Allows the first invoke only.685 return eval_result is None686 ex.continuous_train_and_eval(continuous_eval_predicate_fn=predicate_fn)687 mock_estimator.train.assert_called_once_with(688 input_fn='train_input',689 steps=1234,690 max_steps=test.mock.ANY,691 hooks=test.mock.ANY,692 saving_listeners=test.mock.ANY)693 def test_continuous_train_and_eval_with_default_steps_per_iteration(self):694 mock_estimator = test.mock.Mock(core_estimator.Estimator)695 type(mock_estimator).model_dir = test.mock.PropertyMock(696 return_value='test_dir')697 ex = experiment.Experiment(698 mock_estimator,699 train_input_fn='train_input',700 eval_input_fn='eval_input',701 train_steps_per_iteration=None,702 train_steps=None)703 def predicate_fn(eval_result):704 # Allows the first invoke only.705 return eval_result is None706 ex.continuous_train_and_eval(continuous_eval_predicate_fn=predicate_fn)707 mock_estimator.train.assert_called_once_with(708 input_fn='train_input',709 steps=1000,710 max_steps=test.mock.ANY,711 hooks=test.mock.ANY,712 saving_listeners=test.mock.ANY)713 def test_continuous_train_and_eval_with_invalid_predicate_fn(self):714 for est in self._estimators_for_tests():715 ex = experiment.Experiment(716 est,717 train_input_fn='train_input',718 eval_input_fn='eval_input')719 with self.assertRaisesRegexp(720 ValueError, '`continuous_eval_predicate_fn` must be a callable'):721 ex.continuous_train_and_eval(continuous_eval_predicate_fn='fn')722 def test_continuous_train_and_eval_with_invalid_train_steps_iterations(self):723 for est in self._estimators_for_tests():724 with self.assertRaisesRegexp(725 ValueError, '`train_steps_per_iteration` must be an integer.'):726 experiment.Experiment(727 est,728 train_input_fn='train_input',729 eval_input_fn='eval_input',730 train_steps_per_iteration='123')731 @test.mock.patch.object(server_lib, 'Server')732 def test_run_std_server(self, mock_server):733 # Arrange.734 tf_config = {735 'cluster': self._cluster_spec(),736 'task': {737 'type': run_config_lib.TaskType.PS,738 'index': 1739 }740 }741 with test.mock.patch.dict('os.environ',742 {'TF_CONFIG': json.dumps(tf_config)}):743 config = run_config_lib.RunConfig(744 master='host2:2222',745 num_cores=15,746 gpu_memory_fraction=0.314,)747 for est in self._estimators_for_tests(config):748 ex = experiment.Experiment(749 est, train_input_fn='train_input', eval_input_fn='eval_input')750 # Act.751 ex.run_std_server()752 # Assert.753 mock_server.assert_has_calls(754 [test.mock.call().start(), test.mock.call().join()])755 @test.mock.patch.object(server_lib, 'Server')756 def test_run_std_server_raises_without_cluster_spec(self, mock_server):757 config = run_config_lib.RunConfig(master='host4:2222')758 for est in self._estimators_for_tests(config):759 with self.assertRaises(ValueError):760 ex = experiment.Experiment(761 est,762 train_input_fn='train_input',763 eval_input_fn='eval_input')764 ex.run_std_server()765 def test_test(self):766 for est in self._estimators_for_tests():767 exp_strategy = saved_model_export_utils.make_export_strategy(768 est,769 None if isinstance(est, core_estimator.Estimator) else 'export_input',770 exports_to_keep=None)771 if isinstance(est, core_estimator.Estimator):772 eval_metrics = None773 saving_listeners = 'saving_listeners'774 else:775 eval_metrics = 'eval_metrics'776 saving_listeners = None777 ex = experiment.Experiment(778 est,779 train_input_fn='train_input',780 eval_input_fn='eval_input',781 export_strategies=(exp_strategy,),782 eval_metrics=eval_metrics,783 saving_listeners=saving_listeners)784 ex.test()785 self.assertEqual(1, est.fit_count)786 self.assertEqual(1, est.eval_count)787 self.assertEqual(1, est.export_count)788 def test_continuous_eval_evaluates_checkpoint_once(self):789 for est in self._estimators_for_tests(eval_dict={'global_step': 100}):790 eval_metrics = 'eval_metrics' if not isinstance(791 est, core_estimator.Estimator) else None792 est.fake_checkpoint()793 result = {794 'called': 0,795 'called_with_eval_result': 0,796 }797 # pylint: disable=cell-var-from-loop798 def _predicate_fn(eval_result):799 result['called'] += 1800 if eval_result:801 # If eval_result is not empty nor None, the checkpoint has been802 # evaluated.803 result['called_with_eval_result'] += 1804 # With 300 times of evaluation, this should prove something.805 return result['called'] < 300806 # pylint: enable=cell-var-from-loop807 ex = experiment.Experiment(808 est,809 train_input_fn='train_input',810 eval_input_fn='eval_input',811 eval_metrics=eval_metrics,812 eval_delay_secs=0,813 continuous_eval_throttle_secs=0)814 ex.continuous_eval(evaluate_checkpoint_only_once=True,815 continuous_eval_predicate_fn=_predicate_fn)816 self.assertEqual(0, est.fit_count)817 self.assertEqual(1, est.eval_count)818 self.assertEqual(300, result['called'])819 self.assertEqual(1, result['called_with_eval_result'])820 def test_checkpoint_and_export(self):821 model_dir = tempfile.mkdtemp()822 config = run_config_lib.RunConfig(save_checkpoints_steps=3)823 est = dnn.DNNClassifier(824 n_classes=3,825 feature_columns=[826 feature_column.real_valued_column('feature', dimension=4)827 ],828 hidden_units=[3, 3],...

Full Screen

Full Screen

test_string_literals.py

Source:test_string_literals.py Github

copy

Full Screen

...13inside literals. For bytes literals, this is considered illegal. But14for str literals, those bytes are supposed to be decoded using the15encoding declared for the file (UTF-8 by default).16We have to test this with various file encodings. We also test it with17exec()/eval(), which uses a different code path.18This file is really about correct treatment of encodings and19backslashes. It doesn't concern itself with issues like single20vs. double quotes or singly- vs. triply-quoted strings: that's dealt21with elsewhere (I assume).22"""23import os24import sys25import shutil26import tempfile27import unittest28import warnings29TEMPLATE = r"""# coding: %s30a = 'x'31assert ord(a) == 12032b = '\x01'33assert ord(b) == 134c = r'\x01'35assert list(map(ord, c)) == [92, 120, 48, 49]36d = '\x81'37assert ord(d) == 0x8138e = r'\x81'39assert list(map(ord, e)) == [92, 120, 56, 49]40f = '\u1881'41assert ord(f) == 0x188142g = r'\u1881'43assert list(map(ord, g)) == [92, 117, 49, 56, 56, 49]44h = '\U0001d120'45assert ord(h) == 0x1d12046i = r'\U0001d120'47assert list(map(ord, i)) == [92, 85, 48, 48, 48, 49, 100, 49, 50, 48]48"""49def byte(i):50 return bytes([i])51class TestLiterals(unittest.TestCase):52 from test.support import check_syntax_warning53 def setUp(self):54 self.save_path = sys.path[:]55 self.tmpdir = tempfile.mkdtemp()56 sys.path.insert(0, self.tmpdir)57 def tearDown(self):58 sys.path[:] = self.save_path59 shutil.rmtree(self.tmpdir, ignore_errors=True)60 def test_template(self):61 # Check that the template doesn't contain any non-printables62 # except for \n.63 for c in TEMPLATE:64 assert c == '\n' or ' ' <= c <= '~', repr(c)65 def test_eval_str_normal(self):66 self.assertEqual(eval(""" 'x' """), 'x')67 self.assertEqual(eval(r""" '\x01' """), chr(1))68 self.assertEqual(eval(""" '\x01' """), chr(1))69 self.assertEqual(eval(r""" '\x81' """), chr(0x81))70 self.assertEqual(eval(""" '\x81' """), chr(0x81))71 self.assertEqual(eval(r""" '\u1881' """), chr(0x1881))72 self.assertEqual(eval(""" '\u1881' """), chr(0x1881))73 self.assertEqual(eval(r""" '\U0001d120' """), chr(0x1d120))74 self.assertEqual(eval(""" '\U0001d120' """), chr(0x1d120))75 def test_eval_str_incomplete(self):76 self.assertRaises(SyntaxError, eval, r""" '\x' """)77 self.assertRaises(SyntaxError, eval, r""" '\x0' """)78 self.assertRaises(SyntaxError, eval, r""" '\u' """)79 self.assertRaises(SyntaxError, eval, r""" '\u0' """)80 self.assertRaises(SyntaxError, eval, r""" '\u00' """)81 self.assertRaises(SyntaxError, eval, r""" '\u000' """)82 self.assertRaises(SyntaxError, eval, r""" '\U' """)83 self.assertRaises(SyntaxError, eval, r""" '\U0' """)84 self.assertRaises(SyntaxError, eval, r""" '\U00' """)85 self.assertRaises(SyntaxError, eval, r""" '\U000' """)86 self.assertRaises(SyntaxError, eval, r""" '\U0000' """)87 self.assertRaises(SyntaxError, eval, r""" '\U00000' """)88 self.assertRaises(SyntaxError, eval, r""" '\U000000' """)89 self.assertRaises(SyntaxError, eval, r""" '\U0000000' """)90 def test_eval_str_invalid_escape(self):91 for b in range(1, 128):92 if b in b"""\n\r"'01234567NU\\abfnrtuvx""":93 continue94 with self.assertWarns(DeprecationWarning):95 self.assertEqual(eval(r"'\%c'" % b), '\\' + chr(b))96 with warnings.catch_warnings(record=True) as w:97 warnings.simplefilter('always', category=DeprecationWarning)98 eval("'''\n\\z'''")99 self.assertEqual(len(w), 1)100 self.assertEqual(w[0].filename, '<string>')101 self.assertEqual(w[0].lineno, 1)102 with warnings.catch_warnings(record=True) as w:103 warnings.simplefilter('error', category=DeprecationWarning)104 with self.assertRaises(SyntaxError) as cm:105 eval("'''\n\\z'''")106 exc = cm.exception107 self.assertEqual(w, [])108 self.assertEqual(exc.filename, '<string>')109 self.assertEqual(exc.lineno, 1)110 def test_eval_str_raw(self):111 self.assertEqual(eval(""" r'x' """), 'x')112 self.assertEqual(eval(r""" r'\x01' """), '\\' + 'x01')113 self.assertEqual(eval(""" r'\x01' """), chr(1))114 self.assertEqual(eval(r""" r'\x81' """), '\\' + 'x81')115 self.assertEqual(eval(""" r'\x81' """), chr(0x81))116 self.assertEqual(eval(r""" r'\u1881' """), '\\' + 'u1881')117 self.assertEqual(eval(""" r'\u1881' """), chr(0x1881))118 self.assertEqual(eval(r""" r'\U0001d120' """), '\\' + 'U0001d120')119 self.assertEqual(eval(""" r'\U0001d120' """), chr(0x1d120))120 def test_eval_bytes_normal(self):121 self.assertEqual(eval(""" b'x' """), b'x')122 self.assertEqual(eval(r""" b'\x01' """), byte(1))123 self.assertEqual(eval(""" b'\x01' """), byte(1))124 self.assertEqual(eval(r""" b'\x81' """), byte(0x81))125 self.assertRaises(SyntaxError, eval, """ b'\x81' """)126 self.assertEqual(eval(r""" br'\u1881' """), b'\\' + b'u1881')127 self.assertRaises(SyntaxError, eval, """ b'\u1881' """)128 self.assertEqual(eval(r""" br'\U0001d120' """), b'\\' + b'U0001d120')129 self.assertRaises(SyntaxError, eval, """ b'\U0001d120' """)130 def test_eval_bytes_incomplete(self):131 self.assertRaises(SyntaxError, eval, r""" b'\x' """)132 self.assertRaises(SyntaxError, eval, r""" b'\x0' """)133 def test_eval_bytes_invalid_escape(self):134 for b in range(1, 128):135 if b in b"""\n\r"'01234567\\abfnrtvx""":136 continue137 with self.assertWarns(DeprecationWarning):138 self.assertEqual(eval(r"b'\%c'" % b), b'\\' + bytes([b]))139 with warnings.catch_warnings(record=True) as w:140 warnings.simplefilter('always', category=DeprecationWarning)141 eval("b'''\n\\z'''")142 self.assertEqual(len(w), 1)143 self.assertEqual(w[0].filename, '<string>')144 self.assertEqual(w[0].lineno, 1)145 with warnings.catch_warnings(record=True) as w:146 warnings.simplefilter('error', category=DeprecationWarning)147 with self.assertRaises(SyntaxError) as cm:148 eval("b'''\n\\z'''")149 exc = cm.exception150 self.assertEqual(w, [])151 self.assertEqual(exc.filename, '<string>')152 self.assertEqual(exc.lineno, 1)153 def test_eval_bytes_raw(self):154 self.assertEqual(eval(""" br'x' """), b'x')155 self.assertEqual(eval(""" rb'x' """), b'x')156 self.assertEqual(eval(r""" br'\x01' """), b'\\' + b'x01')157 self.assertEqual(eval(r""" rb'\x01' """), b'\\' + b'x01')158 self.assertEqual(eval(""" br'\x01' """), byte(1))159 self.assertEqual(eval(""" rb'\x01' """), byte(1))160 self.assertEqual(eval(r""" br'\x81' """), b"\\" + b"x81")161 self.assertEqual(eval(r""" rb'\x81' """), b"\\" + b"x81")162 self.assertRaises(SyntaxError, eval, """ br'\x81' """)163 self.assertRaises(SyntaxError, eval, """ rb'\x81' """)164 self.assertEqual(eval(r""" br'\u1881' """), b"\\" + b"u1881")165 self.assertEqual(eval(r""" rb'\u1881' """), b"\\" + b"u1881")166 self.assertRaises(SyntaxError, eval, """ br'\u1881' """)167 self.assertRaises(SyntaxError, eval, """ rb'\u1881' """)168 self.assertEqual(eval(r""" br'\U0001d120' """), b"\\" + b"U0001d120")169 self.assertEqual(eval(r""" rb'\U0001d120' """), b"\\" + b"U0001d120")170 self.assertRaises(SyntaxError, eval, """ br'\U0001d120' """)171 self.assertRaises(SyntaxError, eval, """ rb'\U0001d120' """)172 self.assertRaises(SyntaxError, eval, """ bb'' """)173 self.assertRaises(SyntaxError, eval, """ rr'' """)174 self.assertRaises(SyntaxError, eval, """ brr'' """)175 self.assertRaises(SyntaxError, eval, """ bbr'' """)176 self.assertRaises(SyntaxError, eval, """ rrb'' """)177 self.assertRaises(SyntaxError, eval, """ rbb'' """)178 def test_eval_str_u(self):179 self.assertEqual(eval(""" u'x' """), 'x')180 self.assertEqual(eval(""" U'\u00e4' """), 'ä')181 self.assertEqual(eval(""" u'\N{LATIN SMALL LETTER A WITH DIAERESIS}' """), 'ä')182 self.assertRaises(SyntaxError, eval, """ ur'' """)183 self.assertRaises(SyntaxError, eval, """ ru'' """)184 self.assertRaises(SyntaxError, eval, """ bu'' """)185 self.assertRaises(SyntaxError, eval, """ ub'' """)186 def check_encoding(self, encoding, extra=""):187 modname = "xx_" + encoding.replace("-", "_")188 fn = os.path.join(self.tmpdir, modname + ".py")189 f = open(fn, "w", encoding=encoding)190 try:191 f.write(TEMPLATE % encoding)192 f.write(extra)193 finally:194 f.close()195 __import__(modname)...

Full Screen

Full Screen

LMSAPI.js

Source:LMSAPI.js Github

copy

Full Screen

1function LMSStandardAPI(strStandard){2 3 WriteToDebug("In LMSStandardAPI strStandard=" + strStandard);4 5 if (strStandard == ""){6 WriteToDebug("No standard specified, using NONE");7 strStandard = "NONE";8 }9 eval ("this.Initialize = " + strStandard + "_Initialize");10 eval ("this.Finish = " + strStandard + "_Finish");11 eval ("this.CommitData = " + strStandard + "_CommitData");12 eval ("this.GetStudentID = " + strStandard + "_GetStudentID");13 eval ("this.GetStudentName = " + strStandard + "_GetStudentName");14 eval ("this.GetBookmark = " + strStandard + "_GetBookmark");15 eval ("this.SetBookmark = " + strStandard + "_SetBookmark");16 eval ("this.GetDataChunk = " + strStandard + "_GetDataChunk");17 eval ("this.SetDataChunk = " + strStandard + "_SetDataChunk");18 eval ("this.GetLaunchData = " + strStandard + "_GetLaunchData");19 eval ("this.GetComments = " + strStandard + "_GetComments");20 eval ("this.WriteComment = " + strStandard + "_WriteComment");21 eval ("this.GetLMSComments = " + strStandard + "_GetLMSComments");22 eval ("this.GetAudioPlayPreference = " + strStandard + "_GetAudioPlayPreference");23 eval ("this.GetAudioVolumePreference = " + strStandard + "_GetAudioVolumePreference");24 eval ("this.SetAudioPreference = " + strStandard + "_SetAudioPreference");25 eval ("this.SetLanguagePreference = " + strStandard + "_SetLanguagePreference");26 eval ("this.GetLanguagePreference = " + strStandard + "_GetLanguagePreference");27 eval ("this.SetSpeedPreference = " + strStandard + "_SetSpeedPreference");28 eval ("this.GetSpeedPreference = " + strStandard + "_GetSpeedPreference");29 eval ("this.SetTextPreference = " + strStandard + "_SetTextPreference");30 eval ("this.GetTextPreference = " + strStandard + "_GetTextPreference");31 eval ("this.GetPreviouslyAccumulatedTime = " + strStandard + "_GetPreviouslyAccumulatedTime");32 eval ("this.SaveTime = " + strStandard + "_SaveTime");33 eval ("this.GetMaxTimeAllowed = " + strStandard + "_GetMaxTimeAllowed");34 eval ("this.DisplayMessageOnTimeout = " + strStandard + "_DisplayMessageOnTimeout");35 eval ("this.ExitOnTimeout = " + strStandard + "_ExitOnTimeout");36 eval ("this.GetPassingScore = " + strStandard + "_GetPassingScore");37 eval ("this.SetScore = " + strStandard + "_SetScore");38 eval ("this.GetScore = " + strStandard + "_GetScore");39 eval ("this.GetScaledScore = " + strStandard + "_GetScaledScore");40 41 eval ("this.RecordTrueFalseInteraction = " + strStandard + "_RecordTrueFalseInteraction");42 eval ("this.RecordMultipleChoiceInteraction = " + strStandard + "_RecordMultipleChoiceInteraction");43 eval ("this.RecordFillInInteraction = " + strStandard + "_RecordFillInInteraction");44 eval ("this.RecordMatchingInteraction = " + strStandard + "_RecordMatchingInteraction");45 eval ("this.RecordPerformanceInteraction = " + strStandard + "_RecordPerformanceInteraction");46 eval ("this.RecordSequencingInteraction = " + strStandard + "_RecordSequencingInteraction");47 eval ("this.RecordLikertInteraction = " + strStandard + "_RecordLikertInteraction");48 eval ("this.RecordNumericInteraction = " + strStandard + "_RecordNumericInteraction");49 50 eval ("this.GetEntryMode = " + strStandard + "_GetEntryMode");51 eval ("this.GetLessonMode = " + strStandard + "_GetLessonMode");52 eval ("this.GetTakingForCredit = " + strStandard + "_GetTakingForCredit");53 eval ("this.SetObjectiveScore = " + strStandard + "_SetObjectiveScore");54 eval ("this.SetObjectiveStatus = " + strStandard + "_SetObjectiveStatus");55 eval ("this.GetObjectiveScore = " + strStandard + "_GetObjectiveScore");56 eval ("this.GetObjectiveStatus = " + strStandard + "_GetObjectiveStatus");57 eval ("this.SetObjectiveDescription = " + strStandard + "_SetObjectiveDescription");58 eval ("this.GetObjectiveDescription = " + strStandard + "_GetObjectiveDescription");59 eval ("this.SetFailed = " + strStandard + "_SetFailed");60 eval ("this.SetPassed = " + strStandard + "_SetPassed");61 eval ("this.SetCompleted = " + strStandard + "_SetCompleted");62 eval ("this.ResetStatus = " + strStandard + "_ResetStatus");63 eval ("this.GetStatus = " + strStandard + "_GetStatus"); 64 eval ("this.GetLastError = " + strStandard + "_GetLastError");65 eval ("this.GetLastErrorDesc = " + strStandard + "_GetLastErrorDesc"); 66 67 eval ("this.GetInteractionType = " + strStandard + "_GetInteractionType");68 eval ("this.GetInteractionTimestamp = " + strStandard + "_GetInteractionTimestamp");69 eval ("this.GetInteractionCorrectResponses = " + strStandard + "_GetInteractionCorrectResponses");70 eval ("this.GetInteractionWeighting = " + strStandard + "_GetInteractionWeighting");71 eval ("this.GetInteractionLearnerResponses = " + strStandard + "_GetInteractionLearnerResponses");72 eval ("this.GetInteractionResult = " + strStandard + "_GetInteractionResult");73 eval ("this.GetInteractionLatency = " + strStandard + "_GetInteractionLatency");74 eval ("this.GetInteractionDescription = " + strStandard + "_GetInteractionDescription");75 76 eval ("this.CreateDataBucket = " + strStandard + "_CreateDataBucket");77 eval ("this.GetDataFromBucket = " + strStandard + "_GetDataFromBucket");78 eval ("this.PutDataInBucket = " + strStandard + "_PutDataInBucket");79 eval ("this.DetectSSPSupport = " + strStandard + "_DetectSSPSupport");80 eval ("this.GetBucketInfo = " + strStandard + "_GetBucketInfo");81 82 eval ("this.GetProgressMeasure = " + strStandard + "_GetProgressMeasure");83 eval ("this.SetProgressMeasure = " + strStandard + "_SetProgressMeasure");84 85 eval ("this.SetPointBasedScore = " + strStandard + "_SetPointBasedScore");86 87 this.Standard = strStandard;...

Full Screen

Full Screen

15.1.2.1-1.js

Source:15.1.2.1-1.js Github

copy

Full Screen

...20 * 21 */22/**23 File Name: 15.1.2.1-1.js24 ECMA Section: 15.1.2.1 eval(x)25 if x is not a string object, return x.26 Description:27 Author: christine@netscape.com28 Date: 16 september 199729*/30 var SECTION = "15.1.2.1-1";31 var VERSION = "ECMA_1";32 startTest();33 var TITLE = "eval(x)";34 var BUGNUMBER = "111199";35 writeHeaderToLog( SECTION + " "+ TITLE);36 var testcases = getTestCases();37 test();38function getTestCases() {39 var array = new Array();40 var item = 0;41 array[item++] = new TestCase( SECTION, "eval.length", 1, eval.length );42 array[item++] = new TestCase( SECTION, "delete eval.length", false, delete eval.length );43 array[item++] = new TestCase( SECTION, "var PROPS = ''; for ( p in eval ) { PROPS += p }; PROPS", "", eval("var PROPS = ''; for ( p in eval ) { PROPS += p }; PROPS") );44 array[item++] = new TestCase( SECTION, "eval.length = null; eval.length", 1, eval( "eval.length = null; eval.length") );45// array[item++] = new TestCase( SECTION, "eval.__proto__", Function.prototype, eval.__proto__ );46 // test cases where argument is not a string. should return the argument.47 array[item++] = new TestCase( SECTION, "eval()", void 0, eval() );48 array[item++] = new TestCase( SECTION, "eval(void 0)", void 0, eval( void 0) );49 array[item++] = new TestCase( SECTION, "eval(null)", null, eval( null ) );50 array[item++] = new TestCase( SECTION, "eval(true)", true, eval( true ) );51 array[item++] = new TestCase( SECTION, "eval(false)", false, eval( false ) );52 array[item++] = new TestCase( SECTION, "typeof eval(new String('Infinity/-0')", "object", typeof eval(new String('Infinity/-0')) );53 array[item++] = new TestCase( SECTION, "eval([1,2,3,4,5,6])", "1,2,3,4,5,6", ""+eval([1,2,3,4,5,6]) );54 array[item++] = new TestCase( SECTION, "eval(new Array(0,1,2,3)", "1,2,3", ""+ eval(new Array(1,2,3)) );55 array[item++] = new TestCase( SECTION, "eval(1)", 1, eval(1) );56 array[item++] = new TestCase( SECTION, "eval(0)", 0, eval(0) );57 array[item++] = new TestCase( SECTION, "eval(-1)", -1, eval(-1) );58 array[item++] = new TestCase( SECTION, "eval(Number.NaN)", Number.NaN, eval(Number.NaN) );59 array[item++] = new TestCase( SECTION, "eval(Number.MIN_VALUE)", 5e-308, eval(Number.MIN_VALUE) );60 array[item++] = new TestCase( SECTION, "eval(-Number.MIN_VALUE)", -5e-308, eval(-Number.MIN_VALUE) );61 array[item++] = new TestCase( SECTION, "eval(Number.POSITIVE_INFINITY)", Number.POSITIVE_INFINITY, eval(Number.POSITIVE_INFINITY) );62 array[item++] = new TestCase( SECTION, "eval(Number.NEGATIVE_INFINITY)", Number.NEGATIVE_INFINITY, eval(Number.NEGATIVE_INFINITY) );63 array[item++] = new TestCase( SECTION, "eval( 4294967296 )", 4294967296, eval(4294967296) );64 array[item++] = new TestCase( SECTION, "eval( 2147483648 )", 2147483648, eval(2147483648) );65 return ( array );66}67function test() {68 for ( tc=0; tc < testcases.length; tc++ ) {69 testcases[tc].passed = writeTestCaseResult(70 testcases[tc].expect,71 testcases[tc].actual,72 testcases[tc].description +" = "+ testcases[tc].actual );73 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";74 }75 stopTest();76 return ( testcases );...

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