How to use test_unexpected method in avocado

Best Python code snippet using avocado_python

extra_practice5.py

Source:extra_practice5.py Github

copy

Full Screen

...482 for i, l in enumerate(parm):483 expect = soln[i]484 output = alternatingSum(l)485 # ic(output)486 test_unexpected(output, expect)487 assert (output == expect)488def test_median():489 parm = [490 [],491 [1],492 [1, 2],493 [3, 2, 1],494 [3, 4, 2, 1],495 [3, 4, 5, 2, 1],496 [3.5, 4, 5, 2, 1],497 [6, 3.5, 4, 5, 2, 1],498 ]499 soln = [None, 1, 1.5, 2, 2.5, 3, 3.5, 3.75]500 for i, l in enumerate(parm):501 expect = soln[i]502 output = median(l)503 # ic(output)504 test_unexpected(output, expect)505 assert (output == expect)506def test_isSorted():507 parm = [508 [1, 3, 2],509 [1, 2, 2],510 [5, 3, 4, 2],511 [2, 3, 4, 5],512 [1, 2, 3, 3, 2, 1],513 ]514 soln = [515 False,516 True,517 False,518 True,519 False,520 ]521 for i, l in enumerate(parm):522 expect = soln[i]523 output = isSorted(l)524 # ic(output)525 test_unexpected(output, expect)526 assert (output == expect)527def test_smallestDifference():528 parm = [529 [],530 [19, 2, 83, 6, 27],531 [19, -12, 83, -10, 27],532 [0, 1],533 [0, 2, 99, 97, -1, -2],534 ]535 soln = [536 -1,537 4,538 2,539 1,540 1,541 ]542 for i, l in enumerate(parm):543 expect = soln[i]544 output = smallestDifference(l)545 # ic(output)546 test_unexpected(output, expect)547 assert (output == expect)548def test_lookAndSay():549 parm = [550 [],551 [1, 1, 1],552 [1, 2, 2, 3],553 [1, 1, 2, 3],554 [3, 3, 8, -10, -10, -10],555 [3, 3, 8, 3, 3, 3, 3],556 ]557 soln = [558 [],559 [(3, 1)],560 [(1, 1), (2, 2), (1, 3)],561 [(2, 1), (1, 2), (1, 3)],562 [(2, 3), (1, 8), (3, -10)],563 [(2, 3), (1, 8), (4, 3)],564 ]565 for i, l in enumerate(parm):566 expect = soln[i]567 output = lookAndSay(l)568 # ic(output)569 test_unexpected(output, expect)570 assert (output == expect)571 i = 4572 # ic(inverseLookAndSay(soln[i]))573 assert inverseLookAndSay(soln[i]) == parm[i]574def test_nondestructiveRemoveRepeats():575 parm = [576 [1, 1, 1],577 [1, 3, 5, 3, 3, 2, 1, 7, 5],578 ]579 soln = [580 [1],581 [1, 3, 5, 2, 7],582 ]583 for i, l in enumerate(parm):584 expect = soln[i]585 output = nondestructiveRemoveRepeats(l)586 # ic(output)587 test_unexpected(output, expect)588 assert (output == expect)589 L = [1, 3, 5, 3, 3, 2, 1, 7, 5]590 assert (nondestructiveRemoveRepeats(L) == [1, 3, 5, 2, 7])591 assert (L == [1, 3, 5, 3, 3, 2, 1, 7, 5]) # nondestructive!592 destructiveRemoveRepeats(L)593 assert (L == [1, 3, 5, 2, 7]) # destructive!594 # ic(L)595def test_isPalindromicList():596 parm = [597 [],598 [1, 2, 1],599 [1, 2, 3, 2, 1],600 [1, 2, 3, 3, 1],601 ['a', 'b', 'a', 'b'],602 [(1, 1), (1, 2), (1, 1)],603 [(1, 1), (1, 2), (2, 1)],604 ]605 soln = [606 False,607 True,608 True,609 False,610 False,611 True,612 False,613 ]614 for i, l in enumerate(parm):615 expect = soln[i]616 output = isPalindromicList(l)617 # ic(output)618 test_unexpected(output, expect)619 assert (output == expect)620def test_reverse():621 parm = [622 [1, 2, 3],623 [1, 1, 3],624 [4, 3, 2, 1],625 ]626 soln = [627 [3, 2, 1],628 [3, 1, 1],629 [1, 2, 3, 4],630 ]631 for i, l in enumerate(parm):632 expect = soln[i]633 output = reverse(l)634 # ic(l)635 # assert l == expect636 # test_unexpected(output, expect)637 # assert (output == expect)638def test_vectorSum():639 parm = [640 ([2, 4], [20, 30]),641 ([1, 2, 3], [1, 2, 3]),642 ]643 soln = [644 [22, 34],645 [2, 4, 6],646 ]647 for i, (l1, l2) in enumerate(parm):648 expect = soln[i]649 output = vectorSum(l1, l2)650 # ic(output)651 test_unexpected(output, expect)652 assert (output == expect)653def test_dotProduct():654 parm = [655 ([1, 2, 3], [4, 5, 6]),656 ([2, 2, 3], [4, 5, 6]),657 ([2, 2, 3], [4, 5, 6, 7]),658 ]659 soln = [660 32,661 36,662 36,663 ]664 for i, (l1, l2) in enumerate(parm):665 expect = soln[i]666 output = dotProduct(l1, l2)667 # ic(output)668 test_unexpected(output, expect)669 assert (output == expect)670def test_moveToBack():671 parm = [672 ([2, 3, 3, 4, 1, 5], [3, 2]),673 # ([2, 3, 3, 4, 1, 5, 3, 2], [3, 2]),674 # ([2, 3, 3, 4, 1, 5], [3, 0]),675 ]676 soln = [677 [4, 1, 5, 3, 3, 2],678 [4, 1, 5, 3, 3, 3, 2, 2],679 [2, 4, 1, 5, 3, 3],680 ]681 for i, (l1, l2) in enumerate(parm):682 expect = soln[i]683 output = moveToBack(l1, l2)684 # ic(output)685 # test_unexpected(l1, expect)686 # assert (l1 == expect)687 # l_hit = [3, 0], [2, 0]688 # moveToBack_hit(l_hit, 3)689 # moveToBack_hit(l_hit, 2)690 # ic(l_hit)691def test_binaryListToDecimal():692 parm = [693 [1, 0],694 [1, 0, 1, 1],695 [1, 1, 0, 1],696 ]697 soln = [698 2,699 11,700 13,701 ]702 for i, l in enumerate(parm):703 expect = soln[i]704 output = binaryListToDecimal(l)705 # ic(output)706 test_unexpected(output, expect)707 assert (output == expect)708def test_split():709 parm = [710 ("ab,cd,efg", ","),711 ("ab,cd,efg,", ","),712 (",ab,cd,efg,", ","),713 (", ab ,cd,efg,", ","),714 ]715 soln = [716 ["ab", "cd", "efg"],717 ["ab", "cd", "efg"],718 ["ab", "cd", "efg"],719 [" ab ", "cd", "efg"],720 ]721 for i, (s, d) in enumerate(parm):722 expect = soln[i]723 output = split(s, d)724 # ic(output)725 test_unexpected(output, expect)726 assert output == expect727def test_join():728 parm = [729 (["ab", "cd", "efg"], ","),730 (["ab ", "c d", "e g"], "-"),731 ]732 soln = [733 "ab,cd,efg",734 "ab -c d-e g",735 ]736 for i, (l, d) in enumerate(parm):737 expect = soln[i]738 output = join(l, d)739 # ic(output)740 test_unexpected(output, expect)741 assert output == expect742def test_repeatingPattern():743 parm = [744 [1, 2, 3, 1, 2, 3], # True (b==[1,2,3] and k=2)745 [1, 2, 3, 1, 2],746 [1, 2, 1, 2, 1, 2], # [1,2]747 ]748 soln = [749 True,750 False,751 True,752 ]753 for i, (l) in enumerate(parm):754 expect = soln[i]755 output = repeatingPattern(l)756 # ic(output)757 test_unexpected(output, expect)758 assert output == expect759def test_mostAnagrams():760 parm = [761 ['zoo', 'cat', 'hot', 'act', 'tho', 'cool'],762 ['cat', 'hot', 'tho', 'cool'],763 ['hot', 'tho'],764 # ['cat','hot','act','tho','mach','cham','hamc'],765 ]766 soln = [767 'cat',768 'hot',769 'hot',770 ]771 for i, (l) in enumerate(parm):772 expect = soln[i]773 output = mostAnagrams(l)774 # ic(output)775 test_unexpected(output, expect)776 assert output == expect777def test_map():778 parm = [779 (plus3, [2, 4, 7]),780 (mul2, [2, 4, 7]),781 ]782 soln = [783 [5, 7, 10],784 [4, 8, 14],785 ]786 for i, (f, l) in enumerate(parm):787 expect = soln[i]788 output = map(f, l)789 # ic(output)790 test_unexpected(output, expect)791 assert output == expect792def test_firstNEvenFibonacciNumbers():793 parm = [794 4,795 5,796 ]797 soln = [798 [2, 8, 34, 144],799 [2, 8, 34, 144, 610],800 ]801 for i, n in enumerate(parm):802 expect = soln[i]803 output = firstNEvenFibonacciNumbers(n)804 # ic(output)805 test_unexpected(output, expect)806 assert output == expect807def test_mostCommonName():808 parm = [809 ['Jane', 'Aaron', 'Jane', 'Cindy', 'Aaron'],810 ['Jane', 'Aaron', 'jane', 'Cindy', 'Aaron'],811 ]812 soln = [813 ['Aaron', 'Jane'],814 ['Aaron'],815 ]816 for i, n in enumerate(parm):817 expect = soln[i]818 output = mostCommonName(n)819 # ic(output)820 test_unexpected(output, expect)821 assert output == expect822def test_histogram():823 parm = [824 [73, 62, 91, 74, 100, 77],825 [86, 5],826 [97, 86, 5],827 [73, 62, 91, 74, 100, 77, 5],828 ]829 soln = [830 ('''\83160-69: *83270-79: ***83380-89:83490++ : **\835'''),836 ('''\83710-- : *83810-19:83920-29:84030-39:84140-49:84250-59:84360-69:84470-79:84580-89: *\846'''),847 ('''\84810-- : *84910-19:85020-29:85130-39:85240-49:85350-59:85460-69:85570-79:85680-89: *85790++ : *\858'''),859 ('''\86010-- : *86110-19:86220-29:86330-39:86440-49:86550-59:86660-69: *86770-79: ***86880-89:86990++ : **\870'''),871 ]872 for i, n in enumerate(parm):873 expect = soln[i]874 output = histogram(n)875 # ic(output)876 test_unexpected(output, expect)877 assert output == expect878 l = [879 '10-- : *', '10-19:', '20-29:', '30-39:', '40-49:', '50-59:', '60-69:',880 '70-79:', '80-89: *', '90++ : *'881 ]882 l = "\n".join(l)883 # print(l)884def test_nearestWords_match():885 parm = [886 ('cat', 'at'),887 ('hat', 'ht'),888 ('hat', 'xt'), # add 889 ('cat', 'yat'),890 ('cat', 'cyt'),891 ('cat', 'yct'), # change892 ('hat', 'haty'),893 ('hat', 'htat'),894 ('hat', 'yhat'), # del, in895 ('hat', 'haat'), # del, del896 ('hat', 'htay'),897 ]898 soln = [899 True,900 True,901 False, # add902 True,903 True,904 False, # change905 True,906 True,907 True, # del908 True,909 False,910 ]911 for i, (s, s1) in enumerate(parm):912 expect = soln[i]913 output = nearestWords_match(s, s1)914 # ic(output)915 test_unexpected(output, expect)916 assert output == expect917def test_nearestWords():918 test_nearestWords_match()919 parm = [920 (['cat', 'hat'], 'at'),921 (['cat', 'hat'], 'ct'), # add922 (['cat', 'hat'], 'bat'),923 (['cat', 'hat'], 'cab'), # change924 (['cat', 'hat'], 'htat'),925 (['hat', 'cat'], 'hcat'), # del926 (['cat', 'hat'], 'ab'),927 (['hat', 'cat'], 'cat'),928 ]929 soln = [930 ['cat', 'hat'],931 ['cat'], # add932 ['cat', 'hat'],933 ['cat'], # change934 ['hat'],935 ['hat', 'cat'], # del936 None,937 'cat'938 ]939 for i, (l, s) in enumerate(parm):940 expect = soln[i]941 output = nearestWords(l, s)942 # ic(output)943 test_unexpected(output, expect)944 assert output == expect945def test_bowlingScore():946 parm = [947 [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10],948 [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 1],949 [10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 1, 10],950 [10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 1, 5],951 [1, 9, 2, 8, 3, 7, 4, 6, 5, 5, 6, 4, 7, 3, 8, 2, 9, 1, 5, 5, 6],952 [1, 9, 2, 8, 3, 7, 4, 6, 5, 5, 6, 4, 7, 3, 8, 2, 9, 1, 10, 10, 6],953 [1, 9, 2, 8, 3, 7, 4, 6, 5, 5, 6, 4, 7, 3, 8, 2, 9, 1, 4, 4],954 [1, 2, 2, 2, 3, 2, 4, 2, 5, 2, 6, 2, 7, 2, 8, 0, 9, 0, 1, 0],955 [10, 2, 1, 3, 7, 10, 5, 5, 10, 7, 1, 8, 2, 9, 1, 1, 9, 5],956 ]957 soln = [958 300,959 289,960 279,961 274,962 155,963 170,964 146,965 60,966 147,967 ]968 for i, (l) in enumerate(parm):969 expect = soln[i]970 output = bowlingScore(l)971 # ic(output)972 test_unexpected(output, expect)973 assert output == expect974def test_polynomialToString():975 parm = [976 [2, -3, 0, 4],977 [2, -3, 0, 0],978 [0, -3, 0, 4],979 [5, 2, -3, 0, 4],980 [0, 2, -3, 0, 4],981 [0, 0, -3, 0, 0],982 ]983 soln = [984 "2n^3 - 3n^2 + 4",985 "2n^3 - 3n^2",986 " - 3n^2 + 4",987 "5n^4 + 2n^3 - 3n^2 + 4",988 "2n^3 - 3n^2 + 4",989 " - 3n^2",990 ]991 for i, (l) in enumerate(parm):992 expect = soln[i]993 output = polynomialToString(l)994 # ic(output)995 test_unexpected(output, expect)996 assert output == expect997#################################################998# testAll and main999#################################################1000def testAll():1001 print('testing all...', end='')1002 test_rc2()1003 test_locker_problem()1004 test_isPrime()1005 test_sieve_eratos()1006 test_alternatingSum()1007 test_median()1008 test_isSorted()1009 test_smallestDifference()...

Full Screen

Full Screen

continuity_auth_test.py

Source:continuity_auth_test.py Github

copy

Full Screen

...20 responses = self.auth.perform(achalls)21 self.assertEqual(len(responses), 4)22 for i in xrange(4):23 self.assertEqual(responses[i], "ProofOfPossession%d" % i)24 def test_unexpected(self):25 self.assertRaises(26 errors.ContAuthError, self.auth.perform, [27 achallenges.DVSNI(28 challb=None, domain="0", account_key="invalid_key")])29 def test_chall_pref(self):30 self.assertEqual(31 self.auth.get_chall_pref("example.com"),32 [challenges.ProofOfPossession])33class CleanupTest(unittest.TestCase):34 """Test the Authenticator cleanup function."""35 def setUp(self):36 from letsencrypt.continuity_auth import ContinuityAuthenticator37 self.auth = ContinuityAuthenticator(38 mock.MagicMock(server="demo_server.org"), None)39 def test_unexpected(self):40 unexpected = achallenges.DVSNI(41 challb=None, domain="0", account_key="dummy_key")42 self.assertRaises(errors.ContAuthError, self.auth.cleanup, [unexpected])43def gen_client_resp(chall):44 """Generate a dummy response."""45 return "%s%s" % (chall.__class__.__name__, chall.domain)46if __name__ == '__main__':...

Full Screen

Full Screen

formatters_test.py

Source:formatters_test.py Github

copy

Full Screen

...5 def test_format_2000_get_2K(self):6 assert money_formatter(2000, 1) == '$2K'7 def test_thosuands_floor(self):8 assert money_formatter(2500, 1) == '$2K'9 def test_unexpected(self):10 assert money_formatter(2500, 1) != '$2.5K'11 def test_millions(self):12 assert money_formatter(2500000, 1) == '$2.5M'13 def test_billions(self):14 assert money_formatter(2500000000, 1) == '$2.5B'15class TestThousandsFormatter:16 def test_expected(self):17 assert thousands_formatter(2000, 1) == '2.0'18 def test_format_two_million_get_2000_point_0(self):19 assert thousands_formatter(2000000, 1) == '2000.0'20 def test_unexpected(self):21 assert thousands_formatter(2500000, 1) != '2.5'22@pytest.mark.parametrize("fn", [money_formatter,23 thousands_formatter,24 default_formatter]25 )26def test_formatter_is_protocol(fn):...

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