Best Python code snippet using avocado_python
test_mathematics.py
Source:test_mathematics.py
1from ....testing import raises, VScriptTestCase2from .... import errors3from ....subtypes import mismatch, empty, null, integer, string, double, \4 boolean, error, binary, date, array, dictionary, generic, nothing, \5 nan, infinity, true, false, v_mismatch, v_empty, v_null, v_nothing6class TestBooleanAddition(VScriptTestCase):7 8 def test_empty(self):9 assert self.evaluate("true+empty").is_integer(-1)10 assert self.evaluate("false+empty").is_integer(0)11 def test_null(self):12 assert self.evaluate("true+null").is_null13 assert self.evaluate("false+null").is_null14 def test_integer(self):15 assert self.evaluate("true+123").is_integer(122)16 assert self.evaluate("false+123").is_integer(123)17 def test_double(self):18 assert self.evaluate("true+123.456").is_double(122.456)19 assert self.evaluate("false+123.456").is_double(123.456)20 def test_date(self):21 assert self.evaluate("true+#02.05.1900 10:56:38#").is_date(1900, 5, 1, 10, 56, 38)22 assert self.evaluate("false+#02.05.1900 10:56:38#").is_date(1900, 5, 2, 10, 56, 38)23 def test_string(self):24 assert self.evaluate("true+\"123\"").is_double(122)25 assert self.evaluate("false+\"123\"").is_double(123)26 assert self.evaluate("true+\"123.456\"").is_double(122.456)27 assert self.evaluate("false+\"123.456\"").is_double(123.456)28 with raises(errors.type_mismatch):29 assert self.evaluate("true+\"abc\"")30 with raises(errors.type_mismatch):31 assert self.evaluate("false+\"\"")32 def test_generic(self):33 with raises(errors.object_has_no_property):34 self.evaluate("class object end", "true+new object")35 def test_nothing(self):36 with raises(errors.object_variable_not_set):37 self.evaluate("true+nothing")38 def test_boolean(self):39 assert self.evaluate("true+true").is_integer(-2)40 assert self.evaluate("true+false").is_integer(-1)41 assert self.evaluate("false+true").is_integer(-1)42 assert self.evaluate("false+false").is_integer(0)43 44class TestBooleanSubtraction(VScriptTestCase):45 46 def test_empty(self):47 assert self.evaluate("true-empty").is_integer(-1)48 assert self.evaluate("false-empty").is_integer(0)49 def test_null(self):50 assert self.evaluate("true-null").is_null51 assert self.evaluate("false-null").is_null52 def test_integer(self):53 assert self.evaluate("true-123").is_integer(-124)54 assert self.evaluate("false-123").is_integer(-123)55 def test_double(self):56 assert self.evaluate("true-123.456").is_double(-124.456)57 assert self.evaluate("false-123.456").is_double(-123.456)58 def test_date(self):59 assert self.evaluate("true-#02.05.1900 10:56:38#").is_date(1899, 8, 28, 10, 56, 38)60 assert self.evaluate("false-#02.05.1900 10:56:38#").is_date(1899, 8, 29, 10, 56, 38)61 def test_string(self):62 assert self.evaluate("true-\"123\"").is_double(-124)63 assert self.evaluate("false-\"123\"").is_double(-123)64 assert self.evaluate("true-\"123.456\"").is_double(-124.456)65 assert self.evaluate("false-\"123.456\"").is_double(-123.456)66 with raises(errors.type_mismatch):67 assert self.evaluate("true-\"abc\"")68 with raises(errors.type_mismatch):69 assert self.evaluate("false-\"\"")70 def test_generic(self):71 with raises(errors.object_has_no_property):72 self.evaluate("class object end", "true-new object")73 def test_nothing(self):74 with raises(errors.object_variable_not_set):75 self.evaluate("true-nothing")76 def test_boolean(self):77 assert self.evaluate("true-true").is_integer(0)78 assert self.evaluate("true-false").is_integer(-1)79 assert self.evaluate("false-true").is_integer(1)80 assert self.evaluate("false-false").is_integer(0)81class TestBooleanMultiplication(VScriptTestCase):82 83 def test_empty(self):84 assert self.evaluate("true*empty").is_integer(0)85 assert self.evaluate("false*empty").is_integer(0)86 def test_null(self):87 assert self.evaluate("true*null").is_null88 assert self.evaluate("false*null").is_null89 def test_integer(self):90 assert self.evaluate("true*123").is_integer(-123)91 assert self.evaluate("false*123").is_integer(0)92 def test_double(self):93 assert self.evaluate("true*123.456").is_double(-123.456)94 assert self.evaluate("false*123.456").is_double(0.0)95 def test_date(self):96 assert self.evaluate("true*#02.05.1900 10:56:38#").is_double(-123.45599537037)97 assert self.evaluate("false*#02.05.1900 10:56:38#").is_double(0.0)98 def test_string(self):99 assert self.evaluate("true*\"123\"").is_double(-123)100 assert self.evaluate("false*\"123\"").is_double(0)101 assert self.evaluate("true*\"123.456\"").is_double(-123.456)102 assert self.evaluate("false*\"123.456\"").is_double(0.0)103 with raises(errors.type_mismatch):104 assert self.evaluate("true*\"abc\"")105 with raises(errors.type_mismatch):106 assert self.evaluate("false*\"\"")107 def test_generic(self):108 with raises(errors.object_has_no_property):109 self.evaluate("class object end", "true*new object")110 def test_nothing(self):111 with raises(errors.object_variable_not_set):112 self.evaluate("true*nothing")113 def test_boolean(self):114 assert self.evaluate("true*true").is_integer(1)115 assert self.evaluate("true*false").is_integer(0)116 assert self.evaluate("false*true").is_integer(0)117 assert self.evaluate("false*false").is_integer(0)118class TestBooleanDivision(VScriptTestCase):119 def test_empty(self):120 with raises(errors.division_by_zero):121 self.evaluate("true/empty")122 with raises(errors.division_by_zero):123 self.evaluate("false/empty")124 125 def test_null(self):126 assert self.evaluate("true/null").is_null127 assert self.evaluate("false/null").is_null128 def test_integer(self):129 assert self.evaluate("true/123").is_double(-8.13008130081301E-03)130 assert self.evaluate("false/123").is_double(0.0)131 with raises(errors.division_by_zero):132 self.evaluate("true/0")133 with raises(errors.division_by_zero):134 self.evaluate("false/0")135 def test_double(self):136 assert self.evaluate("true/123.456").is_double(-8.10005184033178E-03)137 assert self.evaluate("false/123.456").is_double(0.0)138 with raises(errors.division_by_zero):139 self.evaluate("true/0.0")140 with raises(errors.division_by_zero):141 self.evaluate("false/0.0")142 def test_date(self):143 assert self.evaluate("true/#02.05.1900 10:56:38#").is_double(-8.10005214408568E-03)144 assert self.evaluate("false/#02.05.1900 10:56:38#").is_double(0.0)145 with raises(errors.division_by_zero):146 self.evaluate("true/#30.12.1899#")147 with raises(errors.division_by_zero):148 self.evaluate("false/#30.12.1899#")149 def test_string(self):150 assert self.evaluate("true/\"123\"").is_double(-8.13008130081301E-03)151 assert self.evaluate("false/\"123\"").is_double(0.0)152 with raises(errors.division_by_zero):153 self.evaluate("true/\"0\"")154 with raises(errors.division_by_zero):155 self.evaluate("false/\"0\"")156 assert self.evaluate("true/\"123.456\"").is_double(-8.10005184033178E-03)157 assert self.evaluate("false/\"123.456\"").is_double(0.0)158 with raises(errors.division_by_zero):159 self.evaluate("true/\"0.0\"")160 with raises(errors.division_by_zero):161 self.evaluate("false/\"0.0\"")162 with raises(errors.type_mismatch):163 self.evaluate("true/\"abc\"")164 with raises(errors.type_mismatch):165 self.evaluate("true/\"\"")166 def test_generic(self):167 with raises(errors.object_has_no_property):168 self.evaluate("class object end", "true/new object")169 def test_nothing(self):170 with raises(errors.object_variable_not_set):171 self.evaluate("true/nothing")172 def test_boolean(self):173 assert self.evaluate("true/true").is_double(1.0)174 with raises(errors.division_by_zero):175 self.evaluate("true/false")176 assert self.evaluate("false/true").is_double(0.0)177 with raises(errors.division_by_zero):178 self.evaluate("false/false")179class TestBooleanIntegerDivision(VScriptTestCase):180 def test_empty(self):181 with raises(errors.division_by_zero):182 self.evaluate("true\\empty")183 with raises(errors.division_by_zero):184 self.evaluate("false\\empty")185 186 def test_null(self):187 assert self.evaluate("true\\null").is_null188 assert self.evaluate("false\\null").is_null189 def test_integer(self):190 assert self.evaluate("true\\123").is_integer(0)191 assert self.evaluate("false\\123").is_integer(0)192 with raises(errors.division_by_zero):193 self.evaluate("true\\0")194 with raises(errors.division_by_zero):195 self.evaluate("false\\0")196 def test_double(self):197 assert self.evaluate("true\\123.456").is_integer(0)198 assert self.evaluate("false\\123.456").is_integer(0)199 with raises(errors.division_by_zero):200 self.evaluate("true\\0.0")201 with raises(errors.division_by_zero):202 self.evaluate("false\\0.0")203 def test_date(self):204 assert self.evaluate("true\\#02.05.1900 10:56:38#").is_integer(0)205 assert self.evaluate("false\\#02.05.1900 10:56:38#").is_integer(0)206 with raises(errors.division_by_zero):207 self.evaluate("true\\#30.12.1899#")208 with raises(errors.division_by_zero):209 self.evaluate("false\\#30.12.1899#")210 def test_string(self):211 assert self.evaluate("true\\\"123\"").is_integer(0)212 assert self.evaluate("false\\\"123\"").is_integer(0)213 with raises(errors.division_by_zero):214 self.evaluate("true\\\"0\"")215 with raises(errors.division_by_zero):216 self.evaluate("false\\\"0\"")217 assert self.evaluate("true\\\"123.456\"").is_integer(0)218 assert self.evaluate("false\\\"123.456\"").is_integer(0)219 with raises(errors.division_by_zero):220 self.evaluate("true\\\"0.0\"")221 with raises(errors.division_by_zero):222 self.evaluate("false\\\"0.0\"")223 with raises(errors.type_mismatch):224 self.evaluate("true\\\"abc\"")225 with raises(errors.type_mismatch):226 self.evaluate("true\\\"\"")227 def test_generic(self):228 with raises(errors.object_has_no_property):229 self.evaluate("class object end", "true\\new object")230 def test_nothing(self):231 with raises(errors.object_variable_not_set):232 self.evaluate("true\\nothing")233 def test_boolean(self):234 assert self.evaluate("true\\true").is_integer(1)235 with raises(errors.division_by_zero):236 self.evaluate("true\\false")237 assert self.evaluate("false\\true").is_integer(0)238 with raises(errors.division_by_zero):239 self.evaluate("false\\false")240class TestBooleanRemainder(VScriptTestCase):241 def test_empty(self):242 with raises(errors.division_by_zero):243 self.evaluate("true mod empty")244 with raises(errors.division_by_zero):245 self.evaluate("false mod empty")246 247 def test_null(self):248 assert self.evaluate("true mod null").is_null249 assert self.evaluate("false mod null").is_null250 def test_integer(self):251 assert self.evaluate("true mod 123").is_integer(-1)252 assert self.evaluate("false mod 123").is_integer(0)253 with raises(errors.division_by_zero):254 self.evaluate("true mod 0")255 with raises(errors.division_by_zero):256 self.evaluate("false mod 0")257 def test_double(self):258 assert self.evaluate("true mod 123.456").is_integer(-1)259 assert self.evaluate("false mod 123.456").is_integer(0)260 with raises(errors.division_by_zero):261 self.evaluate("true mod 0.0")262 with raises(errors.division_by_zero):263 self.evaluate("false mod 0.0")264 def test_date(self):265 assert self.evaluate("true mod #02.05.1900 10:56:38#").is_integer(-1)266 assert self.evaluate("false mod #02.05.1900 10:56:38#").is_integer(0)267 with raises(errors.division_by_zero):268 self.evaluate("true mod #30.12.1899#")269 with raises(errors.division_by_zero):270 self.evaluate("false mod #30.12.1899#")271 def test_string(self):272 assert self.evaluate("true mod \"123\"").is_integer(-1)273 assert self.evaluate("false mod \"123\"").is_integer(0)274 with raises(errors.division_by_zero):275 self.evaluate("true mod \"0\"")276 with raises(errors.division_by_zero):277 self.evaluate("false mod \"0\"")278 assert self.evaluate("true mod \"123.456\"").is_integer(-1)279 assert self.evaluate("false mod \"123.456\"").is_integer(0)280 with raises(errors.division_by_zero):281 self.evaluate("true mod \"0.0\"")282 with raises(errors.division_by_zero):283 self.evaluate("false mod \"0.0\"")284 with raises(errors.type_mismatch):285 self.evaluate("true mod \"abc\"")286 with raises(errors.type_mismatch):287 self.evaluate("true mod \"\"")288 def test_generic(self):289 with raises(errors.object_has_no_property):290 self.evaluate("class object end", "true mod new object")291 def test_nothing(self):292 with raises(errors.object_variable_not_set):293 self.evaluate("true mod nothing")294 def test_boolean(self):295 assert self.evaluate("true mod true").is_integer(0)296 with raises(errors.division_by_zero):297 self.evaluate("true mod false")298 assert self.evaluate("false mod true").is_integer(0)299 with raises(errors.division_by_zero):300 self.evaluate("false mod false")301class TestBooleanExponentiation(VScriptTestCase):302 def test_empty(self):303 assert self.evaluate("true^empty").is_double(1.0)304 assert self.evaluate("false^empty").is_double(1.0)305 def test_null(self):306 assert self.evaluate("true^null").is_null307 assert self.evaluate("false^null").is_null308 def test_integer(self):309 assert self.evaluate("true^3").is_double(-1.0)310 assert self.evaluate("false^3").is_double(0.0)311 assert self.evaluate("true^1").is_double(-1.0)312 assert self.evaluate("false^1").is_double(0.0)313 assert self.evaluate("true^0").is_double(1.0)314 assert self.evaluate("false^0").is_double(1.0)315 def test_double(self):316 with raises(errors.invalid_procedure_call):317 self.evaluate("true^3.456")318 assert self.evaluate("false^3.456").is_double(0.0)319 assert self.evaluate("true^1.0").is_double(-1.0)320 assert self.evaluate("false^1.0").is_double(0.0)321 assert self.evaluate("true^0.0").is_double(1.0)322 assert self.evaluate("false^0.0").is_double(1.0)323 def test_date(self):324 with raises(errors.invalid_procedure_call):325 self.evaluate("true^#02.01.1900 10:56:38#")326 assert self.evaluate("false^#02.01.1900 10:56:38#").is_double(0.0)327 assert self.evaluate("true^#31.12.1899#").is_double(-1.0)328 assert self.evaluate("false^#31.12.1899#").is_double(0.0)329 assert self.evaluate("true^#30.12.1899#").is_double(1.0)330 assert self.evaluate("false^#30.12.1899#").is_double(1.0)331 def test_string(self):332 assert self.evaluate("true^\"3\"").is_double(-1.0)333 assert self.evaluate("false^\"3\"").is_double(0.0)334 assert self.evaluate("true^\"1\"").is_double(-1.0)335 assert self.evaluate("false^\"1\"").is_double(0.0)336 assert self.evaluate("true^\"0\"").is_double(1.0)337 assert self.evaluate("false^\"0\"").is_double(1.0)338 with raises(errors.invalid_procedure_call):339 self.evaluate("true^\"3.456\"")340 assert self.evaluate("false^\"3.456\"").is_double(0.0)341 assert self.evaluate("true^\"1.0\"").is_double(-1.0)342 assert self.evaluate("false^\"1.0\"").is_double(0.0)343 assert self.evaluate("true^\"0.0\"").is_double(1.0)344 assert self.evaluate("false^\"0.0\"").is_double(1.0)345 with raises(errors.type_mismatch):346 self.evaluate("true^\"abc\"")347 with raises(errors.type_mismatch):348 self.evaluate("false^\"\"")349 def test_generic(self):350 with raises(errors.object_has_no_property):351 self.evaluate("class object end", "true^new object")352 def test_nothing(self):353 with raises(errors.object_variable_not_set):354 self.evaluate("true^nothing")355 def test_boolean(self):356 assert self.evaluate("true^true").is_double(-1.0)357 assert self.evaluate("true^false").is_double(1.0)358 with raises(errors.invalid_procedure_call):359 self.evaluate("false^true")...
urls.py
Source:urls.py
1"""Music app URls"""2from django.urls import path3from .views import list_songs, create_song, song_detail, division_by_zero4app_name = 'music'5urlpatterns = [6 path("", list_songs, name="list"), # music:list7 path("create", create_song, name="create"), # music:create8 path("detail/<int:pk>", song_detail, name="detail"), # music:detail9 path("error", division_by_zero, name="division_by_zero"), # music:division_by_zero...
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!!