Best Python code snippet using SeleniumBase
romantest10.py
Source:romantest10.py
1'''Test di unità per roman10.py2Questo programma fa parte di 'Immersione in Python 3', un libro gratuito3sul linguaggio Python per programmatori esperti. Visitate l'indirizzo4http://gpiancastelli.altervista.org/dip3-it per la versione più recente.5'''6import roman107import unittest8class KnownValues(unittest.TestCase):9 known_values = ( (1, 'I'),10 (2, 'II'),11 (3, 'III'),12 (4, 'IV'),13 (5, 'V'),14 (6, 'VI'),15 (7, 'VII'),16 (8, 'VIII'),17 (9, 'IX'),18 (10, 'X'),19 (50, 'L'),20 (100, 'C'),21 (500, 'D'),22 (1000, 'M'),23 (31, 'XXXI'),24 (148, 'CXLVIII'),25 (294, 'CCXCIV'),26 (312, 'CCCXII'),27 (421, 'CDXXI'),28 (528, 'DXXVIII'),29 (621, 'DCXXI'),30 (782, 'DCCLXXXII'),31 (870, 'DCCCLXX'),32 (941, 'CMXLI'),33 (1043, 'MXLIII'),34 (1110, 'MCX'),35 (1226, 'MCCXXVI'),36 (1301, 'MCCCI'),37 (1485, 'MCDLXXXV'),38 (1509, 'MDIX'),39 (1607, 'MDCVII'),40 (1754, 'MDCCLIV'),41 (1832, 'MDCCCXXXII'),42 (1993, 'MCMXCIII'),43 (2074, 'MMLXXIV'),44 (2152, 'MMCLII'),45 (2212, 'MMCCXII'),46 (2343, 'MMCCCXLIII'),47 (2499, 'MMCDXCIX'),48 (2574, 'MMDLXXIV'),49 (2646, 'MMDCXLVI'),50 (2723, 'MMDCCXXIII'),51 (2892, 'MMDCCCXCII'),52 (2975, 'MMCMLXXV'),53 (3051, 'MMMLI'),54 (3185, 'MMMCLXXXV'),55 (3250, 'MMMCCL'),56 (3313, 'MMMCCCXIII'),57 (3408, 'MMMCDVIII'),58 (3501, 'MMMDI'),59 (3610, 'MMMDCX'),60 (3743, 'MMMDCCXLIII'),61 (3844, 'MMMDCCCXLIV'),62 (3888, 'MMMDCCCLXXXVIII'),63 (3940, 'MMMCMXL'),64 (3999, 'MMMCMXCIX'),65 (4000, 'MMMM'),66 (4500, 'MMMMD'),67 (4888, 'MMMMDCCCLXXXVIII'),68 (4999, 'MMMMCMXCIX'))69 def test_to_roman_known_values(self):70 '''to_roman dovrebbe dare un risultato noto con un ingresso noto'''71 for integer, numeral in self.known_values:72 result = roman10.to_roman(integer)73 self.assertEqual(numeral, result)74 def test_from_roman_known_values(self):75 '''from_roman dovrebbe dare un risultato noto con un ingresso noto'''76 for integer, numeral in self.known_values:77 result = roman10.from_roman(numeral)78 self.assertEqual(integer, result)79class ToRomanBadInput(unittest.TestCase):80 def test_too_large(self):81 '''to_roman dovrebbe fallire con numeri grandi'''82 self.assertRaises(roman10.OutOfRangeError, roman10.to_roman, 5000)83 def test_zero(self):84 '''to_roman dovrebbe fallire con il numero 0'''85 self.assertRaises(roman10.OutOfRangeError, roman10.to_roman, 0)86 def test_negative(self):87 '''to_roman dovrebbe fallire con numeri negativi'''88 self.assertRaises(roman10.OutOfRangeError, roman10.to_roman, -1)89 def test_non_integer(self):90 '''to_roman dovrebbe fallire con numeri non interi'''91 self.assertRaises(roman10.NotIntegerError, roman10.to_roman, 0.5)92class FromRomanBadInput(unittest.TestCase):93 def test_too_many_repeated_numerals(self):94 '''from_roman dovrebbe fallire con cifre ripetute troppe volte'''95 for s in ('MMMMM', 'DD', 'CCCC', 'LL', 'XXXX', 'VV', 'IIII'):96 self.assertRaises(roman10.InvalidRomanNumeralError, roman10.from_roman, s)97 def test_repeated_pairs(self):98 '''from_roman dovrebbe fallire con coppie di cifre ripetute'''99 for s in ('CMCM', 'CDCD', 'XCXC', 'XLXL', 'IXIX', 'IVIV'):100 self.assertRaises(roman10.InvalidRomanNumeralError, roman10.from_roman, s)101 def test_malformed_antecedents(self):102 '''from_roman dovrebbe fallire con antecedenti malformati'''103 for s in ('IIMXCC', 'VX', 'DCM', 'CMM', 'IXIV',104 'MCMC', 'XCX', 'IVI', 'LM', 'LD', 'LC'):105 self.assertRaises(roman10.InvalidRomanNumeralError, roman10.from_roman, s)106 def test_blank(self):107 '''from_roman dovrebbe fallire con una stringa vuota'''108 self.assertRaises(roman10.InvalidRomanNumeralError, roman10.from_roman, '')109 def test_non_string(self):110 '''from_roman dovrebbe fallire con ingressi diversi da stringhe'''111 self.assertRaises(roman10.InvalidRomanNumeralError, roman10.from_roman, 1)112class RoundtripCheck(unittest.TestCase):113 def test_roundtrip(self):114 '''from_roman(to_roman(n))==n per tutti gli n'''115 for integer in range(1, 5000):116 numeral = roman10.to_roman(integer)117 result = roman10.from_roman(numeral)118 self.assertEqual(integer, result)119if __name__ == '__main__':120 unittest.main()121# Copyright (c) 2009, Mark Pilgrim, All rights reserved.122# 123# Redistribution and use in source and binary forms, with or without modification,124# are permitted provided that the following conditions are met:125# 126# * Redistributions of source code must retain the above copyright notice,127# this list of conditions and the following disclaimer.128# * Redistributions in binary form must reproduce the above copyright notice,129# this list of conditions and the following disclaimer in the documentation130# and/or other materials provided with the distribution.131# 132# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'133# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE134# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE135# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE136# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR137# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF138# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS139# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN140# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)141# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE...
romantest9.py
Source:romantest9.py
1'''Test di unità per roman9.py2Questo programma fa parte di 'Immersione in Python 3', un libro gratuito3sul linguaggio Python per programmatori esperti. Visitate l'indirizzo4http://gpiancastelli.altervista.org/dip3-it per la versione più recente.5'''6import roman97import unittest8class KnownValues(unittest.TestCase):9 known_values = ( (1, 'I'),10 (2, 'II'),11 (3, 'III'),12 (4, 'IV'),13 (5, 'V'),14 (6, 'VI'),15 (7, 'VII'),16 (8, 'VIII'),17 (9, 'IX'),18 (10, 'X'),19 (50, 'L'),20 (100, 'C'),21 (500, 'D'),22 (1000, 'M'),23 (31, 'XXXI'),24 (148, 'CXLVIII'),25 (294, 'CCXCIV'),26 (312, 'CCCXII'),27 (421, 'CDXXI'),28 (528, 'DXXVIII'),29 (621, 'DCXXI'),30 (782, 'DCCLXXXII'),31 (870, 'DCCCLXX'),32 (941, 'CMXLI'),33 (1043, 'MXLIII'),34 (1110, 'MCX'),35 (1226, 'MCCXXVI'),36 (1301, 'MCCCI'),37 (1485, 'MCDLXXXV'),38 (1509, 'MDIX'),39 (1607, 'MDCVII'),40 (1754, 'MDCCLIV'),41 (1832, 'MDCCCXXXII'),42 (1993, 'MCMXCIII'),43 (2074, 'MMLXXIV'),44 (2152, 'MMCLII'),45 (2212, 'MMCCXII'),46 (2343, 'MMCCCXLIII'),47 (2499, 'MMCDXCIX'),48 (2574, 'MMDLXXIV'),49 (2646, 'MMDCXLVI'),50 (2723, 'MMDCCXXIII'),51 (2892, 'MMDCCCXCII'),52 (2975, 'MMCMLXXV'),53 (3051, 'MMMLI'),54 (3185, 'MMMCLXXXV'),55 (3250, 'MMMCCL'),56 (3313, 'MMMCCCXIII'),57 (3408, 'MMMCDVIII'),58 (3501, 'MMMDI'),59 (3610, 'MMMDCX'),60 (3743, 'MMMDCCXLIII'),61 (3844, 'MMMDCCCXLIV'),62 (3888, 'MMMDCCCLXXXVIII'),63 (3940, 'MMMCMXL'),64 (3999, 'MMMCMXCIX'),65 (4000, 'MMMM'),66 (4500, 'MMMMD'),67 (4888, 'MMMMDCCCLXXXVIII'),68 (4999, 'MMMMCMXCIX'))69 def test_to_roman_known_values(self):70 '''to_roman dovrebbe dare un risultato noto con un ingresso noto'''71 for integer, numeral in self.known_values:72 result = roman9.to_roman(integer)73 self.assertEqual(numeral, result)74 def test_from_roman_known_values(self):75 '''from_roman dovrebbe dare un risultato noto con un ingresso noto'''76 for integer, numeral in self.known_values:77 result = roman9.from_roman(numeral)78 self.assertEqual(integer, result)79class ToRomanBadInput(unittest.TestCase):80 def test_too_large(self):81 '''to_roman dovrebbe fallire con numeri grandi'''82 self.assertRaises(roman9.OutOfRangeError, roman9.to_roman, 5000)83 def test_zero(self):84 '''to_roman dovrebbe fallire con il numero 0'''85 self.assertRaises(roman9.OutOfRangeError, roman9.to_roman, 0)86 def test_negative(self):87 '''to_roman dovrebbe fallire con numeri negativi'''88 self.assertRaises(roman9.OutOfRangeError, roman9.to_roman, -1)89 def test_non_integer(self):90 '''to_roman dovrebbe fallire con numeri non interi'''91 self.assertRaises(roman9.NotIntegerError, roman9.to_roman, 0.5)92class FromRomanBadInput(unittest.TestCase):93 def test_too_many_repeated_numerals(self):94 '''from_roman dovrebbe fallire con cifre ripetute troppe volte'''95 for s in ('MMMMM', 'DD', 'CCCC', 'LL', 'XXXX', 'VV', 'IIII'):96 self.assertRaises(roman9.InvalidRomanNumeralError, roman9.from_roman, s)97 def test_repeated_pairs(self):98 '''from_roman dovrebbe fallire con coppie di cifre ripetute'''99 for s in ('CMCM', 'CDCD', 'XCXC', 'XLXL', 'IXIX', 'IVIV'):100 self.assertRaises(roman9.InvalidRomanNumeralError, roman9.from_roman, s)101 def test_malformed_antecedents(self):102 '''from_roman dovrebbe fallire con antecedenti malformati'''103 for s in ('IIMXCC', 'VX', 'DCM', 'CMM', 'IXIV',104 'MCMC', 'XCX', 'IVI', 'LM', 'LD', 'LC'):105 self.assertRaises(roman9.InvalidRomanNumeralError, roman9.from_roman, s)106 def test_blank(self):107 '''from_roman dovrebbe fallire con una stringa vuota'''108 self.assertRaises(roman9.InvalidRomanNumeralError, roman9.from_roman, '')109 def test_non_string(self):110 '''from_roman dovrebbe fallire con ingressi diversi da stringhe'''111 self.assertRaises(roman9.InvalidRomanNumeralError, roman9.from_roman, 1)112class RoundtripCheck(unittest.TestCase):113 def test_roundtrip(self):114 '''from_roman(to_roman(n))==n per tutti gli n'''115 for integer in range(1, 5000):116 numeral = roman9.to_roman(integer)117 result = roman9.from_roman(numeral)118 self.assertEqual(integer, result)119if __name__ == '__main__':120 unittest.main()121# Copyright (c) 2009, Mark Pilgrim, All rights reserved.122# 123# Redistribution and use in source and binary forms, with or without modification,124# are permitted provided that the following conditions are met:125# 126# * Redistributions of source code must retain the above copyright notice,127# this list of conditions and the following disclaimer.128# * Redistributions in binary form must reproduce the above copyright notice,129# this list of conditions and the following disclaimer in the documentation130# and/or other materials provided with the distribution.131# 132# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'133# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE134# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE135# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE136# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR137# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF138# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS139# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN140# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)141# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE...
romantest8.py
Source:romantest8.py
1'''Test di unità per roman8.py2Questo programma fa parte di 'Immersione in Python 3', un libro gratuito3sul linguaggio Python per programmatori esperti. Visitate l'indirizzo4http://gpiancastelli.altervista.org/dip3-it per la versione più recente.5'''6import roman87import unittest8class KnownValues(unittest.TestCase):9 known_values = ( (1, 'I'),10 (2, 'II'),11 (3, 'III'),12 (4, 'IV'),13 (5, 'V'),14 (6, 'VI'),15 (7, 'VII'),16 (8, 'VIII'),17 (9, 'IX'),18 (10, 'X'),19 (50, 'L'),20 (100, 'C'),21 (500, 'D'),22 (1000, 'M'),23 (31, 'XXXI'),24 (148, 'CXLVIII'),25 (294, 'CCXCIV'),26 (312, 'CCCXII'),27 (421, 'CDXXI'),28 (528, 'DXXVIII'),29 (621, 'DCXXI'),30 (782, 'DCCLXXXII'),31 (870, 'DCCCLXX'),32 (941, 'CMXLI'),33 (1043, 'MXLIII'),34 (1110, 'MCX'),35 (1226, 'MCCXXVI'),36 (1301, 'MCCCI'),37 (1485, 'MCDLXXXV'),38 (1509, 'MDIX'),39 (1607, 'MDCVII'),40 (1754, 'MDCCLIV'),41 (1832, 'MDCCCXXXII'),42 (1993, 'MCMXCIII'),43 (2074, 'MMLXXIV'),44 (2152, 'MMCLII'),45 (2212, 'MMCCXII'),46 (2343, 'MMCCCXLIII'),47 (2499, 'MMCDXCIX'),48 (2574, 'MMDLXXIV'),49 (2646, 'MMDCXLVI'),50 (2723, 'MMDCCXXIII'),51 (2892, 'MMDCCCXCII'),52 (2975, 'MMCMLXXV'),53 (3051, 'MMMLI'),54 (3185, 'MMMCLXXXV'),55 (3250, 'MMMCCL'),56 (3313, 'MMMCCCXIII'),57 (3408, 'MMMCDVIII'),58 (3501, 'MMMDI'),59 (3610, 'MMMDCX'),60 (3743, 'MMMDCCXLIII'),61 (3844, 'MMMDCCCXLIV'),62 (3888, 'MMMDCCCLXXXVIII'),63 (3940, 'MMMCMXL'),64 (3999, 'MMMCMXCIX'))65 def test_to_roman_known_values(self):66 '''to_roman dovrebbe dare un risultato noto con un ingresso noto'''67 for integer, numeral in self.known_values:68 result = roman8.to_roman(integer)69 self.assertEqual(numeral, result)70 def test_from_roman_known_values(self):71 '''from_roman dovrebbe dare un risultato noto con un ingresso noto'''72 for integer, numeral in self.known_values:73 result = roman8.from_roman(numeral)74 self.assertEqual(integer, result)75class ToRomanBadInput(unittest.TestCase):76 def test_too_large(self):77 '''to_roman dovrebbe fallire con numeri grandi'''78 self.assertRaises(roman8.OutOfRangeError, roman8.to_roman, 4000)79 def test_zero(self):80 '''to_roman dovrebbe fallire con il numero 0'''81 self.assertRaises(roman8.OutOfRangeError, roman8.to_roman, 0)82 def test_negative(self):83 '''to_roman dovrebbe fallire con numeri negativi'''84 self.assertRaises(roman8.OutOfRangeError, roman8.to_roman, -1)85 def test_non_integer(self):86 '''to_roman dovrebbe fallire con numeri non interi'''87 self.assertRaises(roman8.NotIntegerError, roman8.to_roman, 0.5)88class FromRomanBadInput(unittest.TestCase):89 def test_too_many_repeated_numerals(self):90 '''from_roman dovrebbe fallire con cifre ripetute troppe volte'''91 for s in ('MMMM', 'DD', 'CCCC', 'LL', 'XXXX', 'VV', 'IIII'):92 self.assertRaises(roman8.InvalidRomanNumeralError, roman8.from_roman, s)93 def test_repeated_pairs(self):94 '''from_roman dovrebbe fallire con coppie di cifre ripetute'''95 for s in ('CMCM', 'CDCD', 'XCXC', 'XLXL', 'IXIX', 'IVIV'):96 self.assertRaises(roman8.InvalidRomanNumeralError, roman8.from_roman, s)97 def test_malformed_antecedents(self):98 '''from_roman dovrebbe fallire con antecedenti malformati'''99 for s in ('IIMXCC', 'VX', 'DCM', 'CMM', 'IXIV',100 'MCMC', 'XCX', 'IVI', 'LM', 'LD', 'LC'):101 self.assertRaises(roman8.InvalidRomanNumeralError, roman8.from_roman, s)102 def test_blank(self):103 '''from_roman dovrebbe fallire con una stringa vuota'''104 self.assertRaises(roman8.InvalidRomanNumeralError, roman8.from_roman, '')105 def test_non_string(self):106 '''from_roman dovrebbe fallire con ingressi diversi da stringhe'''107 self.assertRaises(roman8.InvalidRomanNumeralError, roman8.from_roman, 1)108class RoundtripCheck(unittest.TestCase):109 def test_roundtrip(self):110 '''from_roman(to_roman(n))==n per tutti gli n'''111 for integer in range(1, 4000):112 numeral = roman8.to_roman(integer)113 result = roman8.from_roman(numeral)114 self.assertEqual(integer, result)115if __name__ == '__main__':116 unittest.main()117# Copyright (c) 2009, Mark Pilgrim, All rights reserved.118# 119# Redistribution and use in source and binary forms, with or without modification,120# are permitted provided that the following conditions are met:121# 122# * Redistributions of source code must retain the above copyright notice,123# this list of conditions and the following disclaimer.124# * Redistributions in binary form must reproduce the above copyright notice,125# this list of conditions and the following disclaimer in the documentation126# and/or other materials provided with the distribution.127# 128# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'129# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE130# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE131# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE132# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR133# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF134# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS135# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN136# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)137# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!