How to use test_cmd method in Airtest

Best Python code snippet using Airtest

test.py

Source:test.py Github

copy

Full Screen

1import population, birthDeath, infantMortality, lifeExpectancy, education, gni, hdi, gii, countries, fertility_rates2def population_tests(cnx):3 total_population_tests = 114 tests_passed = 05 # ----------------------------------------------------------------------6 # Tests for: population get7 # ----------------------------------------------------------------------8 # Test 1 : Get all entries in the population tables9 test_cmd = "population all"10 if population.operation(test_cmd.split(" ")[1:], cnx): 11 tests_passed += 112 # Test 2 : Query population data for Canada by country code13 # We know that the dataset contains population information for Canada, so we expect this test to pass14 # The operation returns True if any rows are found15 test_cmd = "population get -code CA" 16 if population.operation(test_cmd.split(" ")[1:], cnx): 17 tests_passed += 118 # Test 3 : Query population data for United States by country name, year and gender19 # This tests if we obtain data for multiple input flags20 # The operation returns True if any rows are found21 test_cmd = "population get -name United_States -year 2000 -gender F" 22 if population.operation(test_cmd.split(" ")[1:], cnx):23 tests_passed += 124 # Test 4 : Query population for a country that does not exist 25 # The operation returns False, if no rows are found, so we should expect a False return below26 test_cmd = "population get -name University_of_Waterloo"27 if population.operation(test_cmd.split(" ")[1:], cnx) == False:28 tests_passed += 129 # ----------------------------------------------------------------------30 # Tests for: population get-range31 # ----------------------------------------------------------------------32 # Test 5 : Query population data for a given range of years33 # The data for Canada exists in the table, so we expect this to be true34 test_cmd = "population get-range -name Canada -start_year 2000 -end_year 2005" 35 if population.operation(test_cmd.split(" ")[1:], cnx):36 tests_passed += 137 # Test 6 : Query population data for range of years that don't exist38 # There is no data for Canada's population between the years 2030 and 2040, so we should expect a False return from the operation39 test_cmd = "population get-range -name Canada -start_year 2030 -end_year 2040" 40 if population.operation(test_cmd.split(" ")[1:], cnx) == False:41 tests_passed += 142 # ----------------------------------------------------------------------43 # Tests for: population add44 # ----------------------------------------------------------------------45 # Test 7 : Update the female population_between_0_10 for Canada in the year 2000 46 # We can update the value of a single row by providing all the primary key values (country_code, country_name, year, gender) to locate the row to be updated followed the value we want to update47 # In this case, it would be the total_midyear_population value48 # The operation returns True if the update was successful49 test_cmd = "population add -code CA -name Canada -year 2000 -gender F -population_between_0_10 100"50 if population.operation(test_cmd.split(" ")[1:], cnx):51 tests_passed += 152 # Test 8 : Insert population data for Canada for the year 203053 # We can use the 'add' command to also insert to new data into the table, as it essentially functions as an upsert54 # This operation returns True if the insertion was successful55 test_cmd = "population add -code CA -name Canada -year 2030 -gender M -total_midyear_population 30 -population_between_0_10 30 -population_between_11_20 30 -population_between_21_30 30 -population_between_31_40 30 -population_between_41_50 30 -population_between_51_60 30 -population_between_61_70 30 -population_between_71_80 30 -population_between_81_90 30 -population_between_91_100 30"56 if population.operation(test_cmd.split(" ")[1:], cnx):57 tests_passed += 158 # Test 9 : A continuation of Test 8 to see if the new entry was actually inserted59 # We query the population data for Canada in 2030 which should have been created in the previous test60 test_cmd = "population get -code CA -year 2030"61 if population.operation(test_cmd.split(" ")[1:], cnx):62 tests_passed += 163 # Test 10 : Inserting a new row which violates the foreign key constaint64 # If we try to add a country with a code that does not exist in the countries table, we should encounter an error65 # This is because the country code in the population table is a foreign key referencing the country code in the countries table66 # The country code ZZ does not exist in the country table 67 test_cmd = "population add -code ZZ -name Canada -year 2030 -gender M -total_midyear_population 30 -population_between_0_10 30 -population_between_11_20 30 -population_between_21_30 30 -population_between_31_40 30 -population_between_41_50 30 -population_between_51_60 30 -population_between_61_70 30 -population_between_71_80 30 -population_between_81_90 30 -population_between_91_100 30"68 if population.operation(test_cmd.split(" ")[1:], cnx) == False:69 tests_passed += 170 # ----------------------------------------------------------------------71 # Tests for: population delete72 # ----------------------------------------------------------------------73 # Test 11 : Deleting the entry created in Test 8 74 # The delete operation will return True if the deletion was successful75 test_cmd = "population delete -name Canada -year 2030 -gender M"76 if population.operation(test_cmd.split(" ")[1:], cnx):77 tests_passed += 178 print(str(tests_passed) + "/" + str(total_population_tests) + " population tests passed")79def birth_death_tests(cnx):80 total_birth_death_tests = 881 tests_passed = 082 # ----------------------------------------------------------------------83 # Tests for: birth_death all84 # ----------------------------------------------------------------------85 # Test 1 : Get all entries in the birth_death table86 test_cmd = "birth_death all"87 if birthDeath.bd(test_cmd.split(" ")[1:], cnx): 88 tests_passed += 189 # ----------------------------------------------------------------------90 # Tests for: birth_death get91 # ----------------------------------------------------------------------92 # Test 2 : Query birth_death data for Canada by country code93 # We know that the dataset contains birth_death information for Canada, so we expect this test to pass94 # The operation returns True if any rows are found95 test_cmd = "birth_death get -code CA" 96 if birthDeath.bd(test_cmd.split(" ")[1:], cnx): 97 tests_passed += 198 # Test 3 : Query birth_death data for United States by country name, year 99 # This tests if we obtain data for multiple input flags100 # The operation returns True if any rows are found101 test_cmd = "birth_death get -name United_States -year 2011" 102 if birthDeath.bd(test_cmd.split(" ")[1:], cnx):103 tests_passed += 1104 # Test 4 : Query birth_death for a country that does not exist 105 # The operation returns False, if no rows are found, so we should expect a False return below106 test_cmd = "birth_death get -name University_of_Waterloo"107 if birthDeath.bd(test_cmd.split(" ")[1:], cnx) == False:108 tests_passed += 1109 # ----------------------------------------------------------------------110 # Tests for: birth_death insert 111 # ----------------------------------------------------------------------112 113 # Test 5 : Insert birth_death data for Canada for the year 2030114 # This operation returns True if the insertion was successful115 test_cmd = "birth_death insert CA Canada 2030 53.6 76.8 4.6 0.25 4.36"116 if birthDeath.bd(test_cmd.split(" ")[1:], cnx):117 tests_passed += 1118 # Test 6 : A continuation of Test 5 to see if the new entry was actually inserted119 # We query the birth_death data for Canada in 2030 which should have been created in the previous test120 test_cmd = "birth_death get -code CA -year 2030"121 if birthDeath.bd(test_cmd.split(" ")[1:], cnx):122 tests_passed += 1123 # ----------------------------------------------------------------------124 # Tests for: birth_death update125 # ----------------------------------------------------------------------126 # Test 7 : Update the growth_rate for Canada in the year 2030 127 # In this case, it would be the growth_rate value128 # The operation returns True if the update was successful129 test_cmd = "birth_death update -code CA -year 2030 -growth_rate 0.7"130 if birthDeath.bd(test_cmd.split(" ")[1:], cnx):131 tests_passed += 1132 # ----------------------------------------------------------------------133 # Tests for: birth_death delete134 # ----------------------------------------------------------------------135 # Test 8 : Deleting the entry created in Test 5136 # The delete operation will return True if the deletion was successful137 test_cmd = "birth_death delete -code CA -year 2030"138 if birthDeath.bd(test_cmd.split(" ")[1:], cnx):139 tests_passed += 1140 print(str(tests_passed) + "/" + str(total_birth_death_tests) + " birth_death tests passed")141def infant_mortality_tests(cnx):142 total_infant_mortality_tests = 8143 tests_passed = 0144 # ----------------------------------------------------------------------145 # Tests for: infant_mortality all146 # ----------------------------------------------------------------------147 # Test 1 : Get all entries in the infant_mortality table148 test_cmd = "infant_mortality all"149 if infantMortality.im(test_cmd.split(" ")[1:], cnx): 150 tests_passed += 1151 # ----------------------------------------------------------------------152 # Tests for: infant_mortality get153 # ----------------------------------------------------------------------154 # Test 2 : Query infant_mortality data for Canada by country code155 # We know that the dataset contains infant_mortality information for Canada, so we expect this test to pass156 # The operation returns True if any rows are found157 test_cmd = "infant_mortality get -code CA" 158 if infantMortality.im(test_cmd.split(" ")[1:], cnx): 159 tests_passed += 1160 # Test 3 : Query infant_mortality data for United States by country name, year 161 # This tests if we obtain data for multiple input flags162 # The operation returns True if any rows are found163 test_cmd = "infant_mortality get -name United_States -year 2014" 164 if infantMortality.im(test_cmd.split(" ")[1:], cnx):165 tests_passed += 1166 # Test 4 : Query infant_mortality for a country that does not exist 167 # The operation returns False, if no rows are found, so we should expect a False return below168 test_cmd = "infant_mortality get -name University_of_Waterloo"169 if infantMortality.im(test_cmd.split(" ")[1:], cnx) == False:170 tests_passed += 1171 # ----------------------------------------------------------------------172 # Tests for: infant_mortality insert 173 # ----------------------------------------------------------------------174 175 # Test 5 : Insert infant_mortality data for Canada for the year 2030176 # This operation returns True if the insertion was successful177 test_cmd = "infant_mortality insert CA Canada 2030 53.6 76.8 4.6"178 if infantMortality.im(test_cmd.split(" ")[1:], cnx):179 tests_passed += 1180 # Test 6 : A continuation of Test 5 to see if the new entry was actually inserted181 # We query the infant_mortality data for Canada in 2030 which should have been created in the previous test182 test_cmd = "infant_mortality get -code CA -year 2030"183 if infantMortality.im(test_cmd.split(" ")[1:], cnx):184 tests_passed += 1185 # ----------------------------------------------------------------------186 # Tests for: infant_mortality update187 # ----------------------------------------------------------------------188 # Test 7 : Update the infant_mortality for Canada in the year 2030 189 # In this case, it would be the infant_mortality value190 # The operation returns True if the update was successful191 test_cmd = "infant_mortality update -code CA -year 2030 -infant_mortality 0.7"192 if infantMortality.im(test_cmd.split(" ")[1:], cnx):193 tests_passed += 1194 # ----------------------------------------------------------------------195 # Tests for: infant_mortality delete196 # ----------------------------------------------------------------------197 # Test 8 : Deleting the entry created in Test 5198 # The delete operation will return True if the deletion was successful199 test_cmd = "infant_mortality delete -code CA -year 2030"200 if infantMortality.im(test_cmd.split(" ")[1:], cnx):201 tests_passed += 1202 print(str(tests_passed) + "/" + str(total_infant_mortality_tests) + " infant_mortality tests passed")203 204def life_expectancy_tests(cnx):205 total_life_expectancy_tests = 8206 tests_passed = 0207 # ----------------------------------------------------------------------208 # Tests for: life_expectancy all209 # ----------------------------------------------------------------------210 # Test 1 : Get all entries in the life_expectancy table211 test_cmd = "life_expectancy all"212 if lifeExpectancy.le(test_cmd.split(" ")[1:], cnx): 213 tests_passed += 1214 # ----------------------------------------------------------------------215 # Tests for: life_expectancy get216 # ----------------------------------------------------------------------217 # Test 2 : Query life_expectancy data for Canada by country code218 # We know that the dataset contains life_expectancy information for Canada, so we expect this test to pass219 # The operation returns True if any rows are found220 test_cmd = "life_expectancy get -code CA" 221 if lifeExpectancy.le(test_cmd.split(" ")[1:], cnx): 222 tests_passed += 1223 # Test 3 : Query life_expectancy data for United States by country name, year 224 # This tests if we obtain data for multiple input flags225 # The operation returns True if any rows are found226 test_cmd = "life_expectancy get -name United_States -year 2014" 227 if lifeExpectancy.le(test_cmd.split(" ")[1:], cnx):228 tests_passed += 1229 # Test 4 : Query life_expectancy for a country that does not exist 230 # The operation returns False, if no rows are found, so we should expect a False return below231 test_cmd = "life_expectancy get -name University_of_Waterloo"232 if lifeExpectancy.le(test_cmd.split(" ")[1:], cnx) == False:233 tests_passed += 1234 # ----------------------------------------------------------------------235 # Tests for: life_expectancy insert 236 # ----------------------------------------------------------------------237 238 # Test 5 : Insert life_expectancy data for Canada for the year 2030239 # This operation returns True if the insertion was successful240 test_cmd = "life_expectancy insert CA Canada 2030 53.6 76.8 4.6"241 if lifeExpectancy.le(test_cmd.split(" ")[1:], cnx):242 tests_passed += 1243 # Test 6 : A continuation of Test 5 to see if the new entry was actually inserted244 # We query the life_expectancy data for Canada in 2030 which should have been created in the previous test245 test_cmd = "life_expectancy get -code CA -year 2030"246 if lifeExpectancy.le(test_cmd.split(" ")[1:], cnx):247 tests_passed += 1248 # ----------------------------------------------------------------------249 # Tests for: life_expectancy update250 # ----------------------------------------------------------------------251 # Test 7 : Update the life_expectancy for Canada in the year 2030 252 # In this case, it would be the life_expectancy value253 # The operation returns True if the update was successful254 test_cmd = "life_expectancy update -code CA -year 2030 -life_expectancy 0.7"255 if lifeExpectancy.le(test_cmd.split(" ")[1:], cnx):256 tests_passed += 1257 # ----------------------------------------------------------------------258 # Tests for: life_expectancy delete259 # ----------------------------------------------------------------------260 # Test 8 : Deleting the entry created in Test 5261 # The delete operation will return True if the deletion was successful262 test_cmd = "life_expectancy delete -code CA -year 2030"263 if lifeExpectancy.le(test_cmd.split(" ")[1:], cnx):264 tests_passed += 1265 print(str(tests_passed) + "/" + str(total_life_expectancy_tests) + " life_expectancy tests passed")266def education_tests(cnx):267 total_education_tests = 8268 tests_passed = 0269 # ----------------------------------------------------------------------270 # Tests for: education all271 # ----------------------------------------------------------------------272 # Test 1 : Get all entries in the education table273 test_cmd = "education all"274 if education.education(test_cmd.split(" ")[1:], cnx): 275 tests_passed += 1276 # ----------------------------------------------------------------------277 # Tests for: education get278 # ----------------------------------------------------------------------279 # Test 2 : Query education data for Canada by country code280 # We know that the dataset contains education information for Canada, so we expect this test to pass281 # The operation returns True if any rows are found282 test_cmd = "education get -code CA" 283 if education.education(test_cmd.split(" ")[1:], cnx): 284 tests_passed += 1285 # Test 3 : Query education data for United States by country name, year 286 # This tests if we obtain data for multiple input flags287 # The operation returns True if any rows are found288 test_cmd = "education get -name United_States -year 2014" 289 if education.education(test_cmd.split(" ")[1:], cnx):290 tests_passed += 1291 # Test 4 : Query education for a country that does not exist 292 # The operation returns False, if no rows are found, so we should expect a False return below293 test_cmd = "education get -name University_of_Waterloo"294 if education.education(test_cmd.split(" ")[1:], cnx) == False:295 tests_passed += 1296 # ----------------------------------------------------------------------297 # Tests for: education insert 298 # ----------------------------------------------------------------------299 300 # Test 5 : Insert education data for Canada for the year 2030301 # This operation returns True if the insertion was successful302 test_cmd = "education insert CA Canada 2030 M 30"303 if education.education(test_cmd.split(" ")[1:], cnx):304 tests_passed += 1305 # Test 6 : A continuation of Test 5 to see if the new entry was actually inserted306 # We query the education data for Canada in 2030 which should have been created in the previous test307 test_cmd = "education get -code CA -year 2030"308 if education.education(test_cmd.split(" ")[1:], cnx):309 tests_passed += 1310 # ----------------------------------------------------------------------311 # Tests for: education update312 # ----------------------------------------------------------------------313 # Test 7 : Update the education for Canada in the year 2030 314 # In this case, it would be the education value315 # The operation returns True if the update was successful316 test_cmd = "education update -code CA -year 2030 -gender M -years_of_schooling 0.7"317 if education.education(test_cmd.split(" ")[1:], cnx):318 tests_passed += 1319 # ----------------------------------------------------------------------320 # Tests for: education delete321 # ----------------------------------------------------------------------322 # Test 8 : Deleting the entry created in Test 5323 # The delete operation will return True if the deletion was successful324 test_cmd = "education delete -code CA -year 2030 -gender M"325 if education.education(test_cmd.split(" ")[1:], cnx):326 tests_passed += 1327 print(str(tests_passed) + "/" + str(total_education_tests) + " education tests passed")328def gni_tests(cnx):329 total_gni_tests = 8330 tests_passed = 0331 # ----------------------------------------------------------------------332 # Tests for: gni all333 # ----------------------------------------------------------------------334 # Test 1 : Get all entries in the gni table335 test_cmd = "gni all"336 if gni.gni(test_cmd.split(" ")[1:], cnx): 337 tests_passed += 1338 # ----------------------------------------------------------------------339 # Tests for: gni get340 # ----------------------------------------------------------------------341 # Test 2 : Query gni data for Canada by country code342 # We know that the dataset contains gni information for Canada, so we expect this test to pass343 # The operation returns True if any rows are found344 test_cmd = "gni get -code CA" 345 if gni.gni(test_cmd.split(" ")[1:], cnx): 346 tests_passed += 1347 # Test 3 : Query gni data for United States by country name, year, gender348 # This tests if we obtain data for multiple input flags349 # The operation returns True if any rows are found350 test_cmd = "gni get -name United_States -year 2014 -gender M" 351 if gni.gni(test_cmd.split(" ")[1:], cnx):352 tests_passed += 1353 # Test 4 : Query gni for a country that does not exist 354 # The operation returns False, if no rows are found, so we should expect a False return below355 test_cmd = "gni get -name University_of_Waterloo"356 if gni.gni(test_cmd.split(" ")[1:], cnx) == False:357 tests_passed += 1358 # ----------------------------------------------------------------------359 # Tests for: gni insert 360 # ----------------------------------------------------------------------361 362 # Test 5 : Insert gni data for Canada for the year 2030363 # This operation returns True if the insertion was successful364 test_cmd = "gni insert CA Canada 2030 M 32532.00"365 if gni.gni(test_cmd.split(" ")[1:], cnx):366 tests_passed += 1367 # Test 6 : A continuation of Test 5 to see if the new entry was actually inserted368 # We query the gni data for Canada in 2030 which should have been created in the previous test369 test_cmd = "gni get -code CA -year 2030"370 if gni.gni(test_cmd.split(" ")[1:], cnx):371 tests_passed += 1372 # ----------------------------------------------------------------------373 # Tests for: gni update374 # ----------------------------------------------------------------------375 # Test 7 : Update the gni for Canada in the year 2030 376 # In this case, it would be the gni value377 # The operation returns True if the update was successful378 test_cmd = "gni update -code CA -year 2030 -gender M -gni 50000.0"379 if gni.gni(test_cmd.split(" ")[1:], cnx):380 tests_passed += 1381 # ----------------------------------------------------------------------382 # Tests for: gni delete383 # ----------------------------------------------------------------------384 # Test 8 : Deleting the entry created in Test 5385 # The delete operation will return True if the deletion was successful386 test_cmd = "gni delete -code CA -year 2030 -gender M"387 if gni.gni(test_cmd.split(" ")[1:], cnx):388 tests_passed += 1389 print(str(tests_passed) + "/" + str(total_gni_tests) + " gni tests passed")390def hdi_tests(cnx):391 total_hdi_tests = 8392 tests_passed = 0393 # ----------------------------------------------------------------------394 # Tests for: hdi all395 # ----------------------------------------------------------------------396 # Test 1 : Get all entries in the hdi table397 test_cmd = "hdi all"398 if hdi.hdi(test_cmd.split(" ")[1:], cnx): 399 tests_passed += 1400 # ----------------------------------------------------------------------401 # Tests for: hdi get402 # ----------------------------------------------------------------------403 # Test 2 : Query hdi data for Canada by country code404 # We know that the dataset contains hdi information for Canada, so we expect this test to pass405 # The operation returns True if any rows are found406 test_cmd = "hdi get -code CA" 407 if hdi.hdi(test_cmd.split(" ")[1:], cnx): 408 tests_passed += 1409 # Test 3 : Query hdi data for United States by country name, year410 # This tests if we obtain data for multiple input flags411 # The operation returns True if any rows are found412 test_cmd = "hdi get -name United_States -year 2014" 413 if hdi.hdi(test_cmd.split(" ")[1:], cnx):414 tests_passed += 1415 # Test 4 : Query hdi for a country that does not exist 416 # The operation returns False, if no rows are found, so we should expect a False return below417 test_cmd = "hdi get -name University_of_Waterloo"418 if hdi.hdi(test_cmd.split(" ")[1:], cnx) == False:419 tests_passed += 1420 # ----------------------------------------------------------------------421 # Tests for: hdi insert 422 # ----------------------------------------------------------------------423 424 # Test 5 : Insert hdi data for Canada for the year 2030425 # This operation returns True if the insertion was successful426 test_cmd = "hdi insert CA Canada 2030 0.70"427 if hdi.hdi(test_cmd.split(" ")[1:], cnx):428 tests_passed += 1429 # Test 6 : A continuation of Test 5 to see if the new entry was actually inserted430 # We query the hdi data for Canada in 2030 which should have been created in the previous test431 test_cmd = "hdi get -code CA -year 2030"432 if hdi.hdi(test_cmd.split(" ")[1:], cnx):433 tests_passed += 1434 # ----------------------------------------------------------------------435 # Tests for: hdi update436 # ----------------------------------------------------------------------437 # Test 7 : Update the hdi for Canada in the year 2030 438 # In this case, it would be the hdi value439 # The operation returns True if the update was successful440 test_cmd = "hdi update -code CA -year 2030 -hdi 0.90"441 if hdi.hdi(test_cmd.split(" ")[1:], cnx):442 tests_passed += 1443 # ----------------------------------------------------------------------444 # Tests for: hdi delete445 # ----------------------------------------------------------------------446 # Test 8 : Deleting the entry created in Test 5447 # The delete operation will return True if the deletion was successful448 test_cmd = "hdi delete -code CA -year 2030"449 if hdi.hdi(test_cmd.split(" ")[1:], cnx):450 tests_passed += 1451 print(str(tests_passed) + "/" + str(total_hdi_tests) + " hdi tests passed")452def gii_tests(cnx):453 total_gii_tests = 8454 tests_passed = 0455 # ----------------------------------------------------------------------456 # Tests for: gii all457 # ----------------------------------------------------------------------458 # Test 1 : Get all entries in the gii table459 test_cmd = "gii all"460 if gii.gii(test_cmd.split(" ")[1:], cnx): 461 tests_passed += 1462 # ----------------------------------------------------------------------463 # Tests for: gii get464 # ----------------------------------------------------------------------465 # Test 2 : Query gii data for Canada by country code466 # We know that the dataset contains gii information for Canada, so we expect this test to pass467 # The operation returns True if any rows are found468 test_cmd = "gii get -code CA" 469 if gii.gii(test_cmd.split(" ")[1:], cnx): 470 tests_passed += 1471 # Test 3 : Query gii data for United States by country name, year472 # This tests if we obtain data for multiple input flags473 # The operation returns True if any rows are found474 test_cmd = "gii get -name United_States -year 2014" 475 if gii.gii(test_cmd.split(" ")[1:], cnx):476 tests_passed += 1477 # Test 4 : Query gii for a country that does not exist 478 # The operation returns False, if no rows are found, so we should expect a False return below479 test_cmd = "gii get -name University_of_Waterloo"480 if gii.gii(test_cmd.split(" ")[1:], cnx) == False:481 tests_passed += 1482 # ----------------------------------------------------------------------483 # Tests for: gii insert 484 # ----------------------------------------------------------------------485 486 # Test 5 : Insert gii data for Canada for the year 2030487 # This operation returns True if the insertion was successful488 test_cmd = "gii insert CA Canada 2030 0.70"489 if gii.gii(test_cmd.split(" ")[1:], cnx):490 tests_passed += 1491 # Test 6 : A continuation of Test 5 to see if the new entry was actually inserted492 # We query the gii data for Canada in 2030 which should have been created in the previous test493 test_cmd = "gii get -code CA -year 2030"494 if gii.gii(test_cmd.split(" ")[1:], cnx):495 tests_passed += 1496 # ----------------------------------------------------------------------497 # Tests for: gii update498 # ----------------------------------------------------------------------499 # Test 7 : Update the gii for Canada in the year 2030 500 # In this case, it would be the gii value501 # The operation returns True if the update was successful502 test_cmd = "gii update -code CA -year 2030 -gii 0.90"503 if gii.gii(test_cmd.split(" ")[1:], cnx):504 tests_passed += 1505 # ----------------------------------------------------------------------506 # Tests for: gii delete507 # ----------------------------------------------------------------------508 # Test 8 : Deleting the entry created in Test 5509 # The delete operation will return True if the deletion was successful510 test_cmd = "gii delete -code CA -year 2030"511 if gii.gii(test_cmd.split(" ")[1:], cnx):512 tests_passed += 1513 print(str(tests_passed) + "/" + str(total_gii_tests) + " gii tests passed")514def country_tests(cnx):515 total_country_tests = 8516 tests_passed = 0517 # ----------------------------------------------------------------------518 # Tests for: country all519 # ----------------------------------------------------------------------520 # Test 1 : Get all entries in the country table521 test_cmd = "country all"522 if countries.country(test_cmd.split(" ")[1:], cnx): 523 tests_passed += 1524 # ----------------------------------------------------------------------525 # Tests for: country get526 # ----------------------------------------------------------------------527 # Test 2 : Query country data for Canada by country code528 # We know that the dataset contains country information for Canada, so we expect this test to pass529 # The operation returns True if any rows are found530 test_cmd = "country get -code CA" 531 if countries.country(test_cmd.split(" ")[1:], cnx): 532 tests_passed += 1533 # Test 3 : Query country data for United States by country name534 # This tests if we obtain data for multiple input flags535 # The operation returns True if any rows are found536 test_cmd = "country get -name United_States" 537 if countries.country(test_cmd.split(" ")[1:], cnx):538 tests_passed += 1539 # Test 4 : Query a country that does not exist 540 # The operation returns False, if no rows are found, so we should expect a False return below541 test_cmd = "country get -name University_of_Waterloo"542 if countries.country(test_cmd.split(" ")[1:], cnx) == False:543 tests_passed += 1544 # ----------------------------------------------------------------------545 # Tests for: country insert 546 # ----------------------------------------------------------------------547 548 # Test 5 : Insert country data for Test_Country 549 # This operation returns True if the insertion was successful550 test_cmd = "country insert ZZ Test_Country 10000.0"551 if countries.country(test_cmd.split(" ")[1:], cnx):552 tests_passed += 1553 # Test 6 : A continuation of Test 5 to see if the new entry was actually inserted554 # We query the Test_Country with country code which should have been created in the previous test555 test_cmd = "country get -code ZZ"556 if countries.country(test_cmd.split(" ")[1:], cnx):557 tests_passed += 1558 # ----------------------------------------------------------------------559 # Tests for: country update560 # ----------------------------------------------------------------------561 # Test 7 : Update the area for Test_Country 562 # The operation returns True if the update was successful563 test_cmd = "country update -code ZZ -area 99999.0"564 if countries.country(test_cmd.split(" ")[1:], cnx):565 tests_passed += 1566 # ----------------------------------------------------------------------567 # Tests for: country delete568 # ----------------------------------------------------------------------569 # Test 8 : Deleting the entry created in Test 5570 # The delete operation will return True if the deletion was successful571 test_cmd = "country delete -code ZZ"572 if countries.country(test_cmd.split(" ")[1:], cnx):573 tests_passed += 1574 print(str(tests_passed) + "/" + str(total_country_tests) + " country tests passed")575def fertility_rates_tests(cnx):576 total_fertility_rates_tests = 8577 tests_passed = 0578 # ----------------------------------------------------------------------579 # Tests for: fertility_rates get580 # ----------------------------------------------------------------------581 # Test 1 : Get all entries in the fertility_rates tables582 test_cmd = "fertility_rates all"583 if fertility_rates.operation(test_cmd.split(" ")[1:], cnx): 584 tests_passed += 1585 # Test 2 : Query fertility_rates data for Canada by country code586 # We know that the dataset contains fertility_rates information for Canada, so we expect this test to pass587 # The operation returns True if any rows are found588 test_cmd = "fertility_rates get -code CA" 589 if fertility_rates.operation(test_cmd.split(" ")[1:], cnx): 590 tests_passed += 1591 # Test 3 : Query fertility_rates data for United States by country name, year and gender592 # This tests if we obtain data for multiple input flags593 # The operation returns True if any rows are found594 test_cmd = "fertility_rates get -name United_States -year 2014" 595 if fertility_rates.operation(test_cmd.split(" ")[1:], cnx):596 tests_passed += 1597 # Test 4 : Query fertility_rates for a country that does not exist 598 # The operation returns False, if no rows are found, so we should expect a False return below599 test_cmd = "fertility_rates get -name University_of_Waterloo"600 if fertility_rates.operation(test_cmd.split(" ")[1:], cnx) == False:601 tests_passed += 1602 # ----------------------------------------------------------------------603 # Tests for: fertility_rates get-range604 # ----------------------------------------------------------------------605 # Test 5 : Query fertility_rates data for a given range of years606 # The data for Canada exists in the table, so we expect this to be true607 test_cmd = "fertility_rates get-range -name Canada -start_year 2000 -end_year 2005" 608 if fertility_rates.operation(test_cmd.split(" ")[1:], cnx):609 tests_passed += 1610 # Test 6 : Query fertility_rates data for range of years that don't exist611 # There is no data for Canada's fertility_rates between the years 2030 and 2040, so we should expect a False return from the operation612 test_cmd = "fertility_rates get-range -name Canada -start_year 2030 -end_year 2040" 613 if fertility_rates.operation(test_cmd.split(" ")[1:], cnx) == False:614 tests_passed += 1615 # ----------------------------------------------------------------------616 # Tests for: fertility_rates add617 # ----------------------------------------------------------------------618 # Test 7 : Update the fertility_rate_15_19 for Canada in the year 2000 619 # The operation returns True if the update was successful620 test_cmd = "fertility_rates add -code CA -name Canada -year 2000 -fertility_rate_15_19 100"621 if fertility_rates.operation(test_cmd.split(" ")[1:], cnx):622 tests_passed += 1623 # ----------------------------------------------------------------------624 # Tests for: fertility_rates delete625 # ----------------------------------------------------------------------626 # Test 8 : Deleting the entry created in Test 8 627 # The delete operation will return True if the deletion was successful628 test_cmd = "fertility_rates delete -name Canada -year 2030"629 if fertility_rates.operation(test_cmd.split(" ")[1:], cnx):630 tests_passed += 1631 print(str(tests_passed) + "/" + str(total_fertility_rates_tests) + " fertility_rates tests passed")632def run_tests(cnx, suite):633 if suite == "population": 634 population_tests(cnx)635 elif suite == "birth_death":636 birth_death_tests(cnx)637 elif suite == "infant_mortality":638 infant_mortality_tests(cnx)639 elif suite == "life_expectancy":640 life_expectancy_tests(cnx)641 elif suite == "education":642 education_tests(cnx)643 elif suite == "gni":644 gni_tests(cnx)645 elif suite == "hdi":646 hdi_tests(cnx)647 elif suite == "gii":648 gii_tests(cnx)649 elif suite == "country":650 country_tests(cnx)651 elif suite == "fertility_rates":652 fertility_rates_tests(cnx)653 else:...

Full Screen

Full Screen

wscript

Source:wscript Github

copy

Full Screen

...32 d_node = bld.path.make_node('path_to_record')33 dumpf_default = d_node.abspath()34 def make_cmd(cmd, based=proj_cwd, dumpf=dumpf_default):35 return list(cmd) + ['--based=%s' % based, '--dumpf=%s' % dumpf]36 def test_cmd(cmd, cwd, test_name, cwd_dir='.', top_dir='.', out_dir='tmp_out', run_dir='.', launch_dir='.'):37 cmd = make_cmd(cmd)38 try:39 run_command(bld, cmd, cwd=cwd)40 v = ConfigSet.ConfigSet(dumpf_default)41 finally:42 for k in bld.path.ant_glob('**/path_to_record'):43 k.delete()44 err = []45 def check_err(got, expected, var_name):46 if got != expected:47 Logs.pprint('RED', '- %s: %s -> got:%r expected:%r' % (test_name, var_name, got, expected))48 err.append(var_name)49 check_err(v.cwd_dir, cwd_dir, 'cwd')50 check_err(v.top_dir, top_dir, 'top')51 check_err(v.run_dir, run_dir, 'run')52 check_err(v.out_dir, out_dir, 'out')53 check_err(v.launch_dir, launch_dir, 'launch')54 if err:55 failures.append(test_name)56 else:57 Logs.pprint('GREEN', '- %s: ok' % test_name)58 exe = os.path.abspath(os.path.join(Context.launch_dir, sys.argv[0]))59 cleanup(bld)60 test_cmd([exe, 'configure'], proj_cwd, 'regular configure')61 test_cmd([exe], proj_cwd, ' regular build from top')62 test_cmd([exe], proj_out_cwd, ' regular build from out', launch_dir='tmp_out')63 test_cmd([exe], proj_sub_cwd, ' regular build from subfolder', launch_dir='sub')64 cleanup(bld)65 test_cmd([exe, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], proj_cwd, 'configure with top/out from proj cwd')66 test_cmd([exe], proj_cwd, ' next build from top')67 test_cmd([exe], proj_out_cwd, ' next build from out', launch_dir='tmp_out')68 test_cmd([exe], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')69 test_cmd([exe, '--top=%s' % proj_cwd, '--out=foobar'], proj_cwd,70 ' next build from top, verify out_dir==lock_file.out_dir')71 test_cmd([exe, '--top=%s' % proj_cwd, '--out=foobar'], proj_sub_cwd,72 ' next build from subfolder, verify out_dir==lock_file.out_dir', launch_dir='sub')73 cleanup(bld)74 test_cmd([exe, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], up_cwd, 'configure with top/out from up cwd',75 launch_dir='..')76 test_cmd([exe], proj_cwd, ' next build from top')77 test_cmd([exe], proj_out_cwd, ' next build from out', launch_dir='tmp_out')78 test_cmd([exe], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')79 cleanup(bld)80 test_cmd([wscript, 'configure'], proj_cwd, 'wscript configure')81 test_cmd([wscript], proj_cwd, ' next build from top')82 test_cmd([wscript], proj_out_cwd, ' next build from out', launch_dir='tmp_out')83 test_cmd([wscript], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')84 cleanup(bld)85 test_cmd([wscript, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], proj_cwd, 'wscript configure with top/out from proj cwd')86 test_cmd([wscript], proj_cwd, ' next build from top')87 test_cmd([wscript], proj_out_cwd, ' next build from out', launch_dir='tmp_out')88 test_cmd([wscript], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')89 cleanup(bld)90 test_cmd([wscript, 'configure', '--top=%s' % proj_cwd, '--out=%s' % proj_out_cwd], up_cwd, 'wscript configure with top/out from up cwd',91 launch_dir='..')92 test_cmd([wscript], proj_cwd, ' next build from top')93 test_cmd([wscript], proj_out_cwd, ' next build from out', launch_dir='tmp_out')94 test_cmd([wscript], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')95 cleanup(bld)96 test_cmd([exe, '--top=%s' % proj_cwd], proj_cwd, 'autoconfig')97 cleanup(bld)98 test_cmd([wscript, 'configure', '--top=project', '--out=project/tmp_out'], up_cwd, 'wscript configure with relative top/out from up cwd',99 launch_dir='..')100 test_cmd([wscript], proj_cwd, ' next build from top')101 test_cmd([wscript], proj_out_cwd, ' next build from out', launch_dir='tmp_out')102 test_cmd([wscript], proj_sub_cwd, ' next build from subfolder', launch_dir='sub')103 cleanup(bld)104 test_cmd([exe, '--force-autoconfig', '--top=project'], up_cwd, 'autoconfig from up 1', launch_dir='..')105 os.remove(dumpf_default + '_autoconfig')106 test_cmd([exe, '--force-autoconfig', '--top=project'], up_cwd, 'autoconfig from up 2', launch_dir='..')107 os.remove(dumpf_default + '_autoconfig')108 test_cmd([exe, '--force-autoconfig', '--out=badout'], proj_cwd, 'autoconfig with clobber')109 cleanup(bld)110 if failures:...

Full Screen

Full Screen

git_test.py

Source:git_test.py Github

copy

Full Screen

...4# Add the ../tools directory to the path so that we can import git_utils.py5sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'hooks'))6from git_utils import *7#============================================================================8def test_cmd(cmd, expected_stdout, expected_status, *args, **kwargs):9 global status10 print 'test: \'git.%s %s\' == %s' % (cmd, ' '.join(args), expected_stdout)11 # get a pointer to the command in our git library12 try:13 methodToCall = getattr(git, cmd)14 except:15 print 'This command does not exist in git_utils.py : %s' % cmd16 cmd_status = 117 exit(1)18 # Run the command and note whether there was a failure. Might be expected.19 cmd_status = 020 try:21 if len(args) == 0 and len(kwargs) == 0:22 cmd_stdout = methodToCall()23 elif len(args) == 0 and len(kwargs) != 0:24 cmd_stdout = methodToCall(**kwargs)25 elif len(args) != 0 and len(kwargs) == 0:26 cmd_stdout = methodToCall(*args)27 else:28 cmd_stdout = methodToCall(*args, **kwargs)29 except:30 cmd_status = 131 # expect to succeed32 if (expected_status == 0):33 if (cmd_status == 1):34 print 'FAIL : command failed'35 status = 'FAIL'36 elif (cmd_stdout == expected_stdout):37 print 'PASS'38 else:39 print 'FAIL : output was %s' % cmd_stdout40 status = 'FAIL'41 else:42 if (cmd_status == 1):43 print 'PASS'44 else:45 print 'FAIL : expected command to fail, but it did not fail.'46 status = 'FAIL'47 print48 return49#============================================================================50git = git_utils()51status = 'PASS'52os.chdir('/home/atull/repos/linux-socfpga')53# Test each git command in git_utils.py in alpha order:54print 'Basic git operations...'55test_cmd('cat_file', 'commit', 0, '-t', 'HEAD')56test_cmd('cat_file', True, 0, '-e', 'HEAD')57test_cmd('cat_file', False, 0, '-e', 'HEasdfasdfasdfAD')58test_cmd('config', 'origin\n', 0, 'branch.socfpga-3.8.remote')59test_cmd('config', '', 1, 'brdddanch.socfpga-3.8.remote')60#test_cmd('fetch', '',61patches = [ '0001-FogBugz-119143-Base-socfpga.dtsi-is-incomplete.patch', '0002-FogBugz-1011105-document-gpio-dw-device-tree-binding.patch', '0003-FogBugz-108269-Enable-PMU-through-the-CTI.patch' ]62test_cmd('format_patch', patches, 0, '-3', '7fc7cbf')63for patch in patches:64 os.remove(patch)65test_cmd('describe', 'v3.8-85-g7fc7cbf', 0, '7fc7cbf8798')66test_cmd('describe', '', 1, 'asdflkjsdfldsfd')67#test_cmd('diff_tree', 'create mode 100644 Documentation/devicetree/bindings/gpio/gpio-dw.txt', 0, 'f50d4b0^', 'f50d4b0')68test_cmd('log', '7fc7cbf', 0, '-1', '--pretty=format:%h', '7fc7cbf8798')69#test_cmd('show',70#test_cmd('status',71print 'Higher level functions...'72test_cmd('author_email', 'dinguyen@altera.com', 0, '7fc7cbf')73test_cmd('author_full', 'Dinh Nguyen <dinguyen@altera.com>', 0, '7fc7cbf')74test_cmd('author_name', 'Dinh Nguyen', 0, '7fc7cbf')75#test_cmd('branch_name',76patches = [ '0001-FogBugz-119143-Base-socfpga.dtsi-is-incomplete.patch', '0002-FogBugz-1011105-document-gpio-dw-device-tree-binding.patch', '0003-FogBugz-108269-Enable-PMU-through-the-CTI.patch' ]77test_cmd('create_patches', patches, 0, num_commits=3, rev='7fc7cbf')78for patch in patches:79 os.remove(patch)80#test_cmd('header',81test_cmd('in_repo', True, 0, )82test_cmd('log_of_hashes', 'dc45ca3bc91010c04f3c563e3621e14c7b9dddb4\n46c7ce960c1ea706a13d94ec4abcc30a10ef19b9\n7bb66e6a0cabf95a46abd02dcd329f17d4e4b8a8', 0, 'dc45ca3^^^', 'dc45ca3')83test_cmd('parent_hashes', ['7c45512df987c5619db041b5c9b80d281e26d3db', '9937c026820baabd1e908a9c1e6bdc846293000a'], 0, 'v3.8^')84test_cmd('rev_to_hash', '19f949f52599ba7c3f67a5897ac6be14bfcb1200', 0, 'v3.8')85test_cmd('remote_for_branch', 'origin', 0, 'master')86test_cmd('remote_for_branch', 'origin', 1, 'maasdfasdfster')87test_cmd('remote_url', 'gitolite@at-git:linux-socfpga', 0, 'origin')88test_cmd('repo_is_bare', False, 0)89test_cmd('repo_name', 'linux-socfpga', 0)90test_cmd('subject', 'Linux 3.8', 0, 'v3.8')91test_cmd('toplevel', '/home/atull/repos/linux-socfpga', 0)92#test_cmd('up_to_date',93print '===================='94print 'Overall status: %s' % status95print '===================='96exit(0)97print git.branch_name()98exit(0)99try:100 patches = git.create_patches(output_path='lala_patches', num_commits=3, rev='HEAD^^^')101except:102 print 'I could not create the patches, sir.'103print patches...

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