How to use assertOutput method in Slash

Best Python code snippet using slash

tests.py

Source:tests.py Github

copy

Full Screen

...123 return stdout, stderr124 def assertNoOutput(self, stream):125 "Utility assertion: assert that the given stream is empty"126 self.assertEquals(len(stream), 0, "Stream should be empty: actually contains '%s'" % stream)127 def assertOutput(self, stream, msg):128 "Utility assertion: assert that the given message exists in the output"129 self.failUnless(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream))130##########################################################################131# DJANGO ADMIN TESTS132# This first series of test classes checks the environment processing133# of the django-admin.py script134##########################################################################135class DjangoAdminNoSettings(AdminScriptTestCase):136 "A series of tests for django-admin.py when there is no settings.py file."137 def test_builtin_command(self):138 "no settings: django-admin builtin commands fail with an import error when no settings provided"139 args = ['sqlall','admin_scripts']140 out, err = self.run_django_admin(args)141 self.assertNoOutput(out)142 self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')143 def test_builtin_with_bad_settings(self):144 "no settings: django-admin builtin commands fail if settings file (from argument) doesn't exist"145 args = ['sqlall','--settings=bad_settings', 'admin_scripts']146 out, err = self.run_django_admin(args)147 self.assertNoOutput(out)148 self.assertOutput(err, "Could not import settings 'bad_settings'")149 def test_builtin_with_bad_environment(self):150 "no settings: django-admin builtin commands fail if settings file (from environment) doesn't exist"151 args = ['sqlall','admin_scripts']152 out, err = self.run_django_admin(args,'bad_settings')153 self.assertNoOutput(out)154 self.assertOutput(err, "Could not import settings 'bad_settings'")155class DjangoAdminDefaultSettings(AdminScriptTestCase):156 """A series of tests for django-admin.py when using a settings.py file that157 contains the test application.158 """159 def setUp(self):160 self.write_settings('settings.py')161 def tearDown(self):162 self.remove_settings('settings.py')163 def test_builtin_command(self):164 "default: django-admin builtin commands fail with an import error when no settings provided"165 args = ['sqlall','admin_scripts']166 out, err = self.run_django_admin(args)167 self.assertNoOutput(out)168 self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')169 def test_builtin_with_settings(self):170 "default: django-admin builtin commands succeed if settings are provided as argument"171 args = ['sqlall','--settings=settings', 'admin_scripts']172 out, err = self.run_django_admin(args)173 self.assertNoOutput(err)174 self.assertOutput(out, 'CREATE TABLE')175 def test_builtin_with_environment(self):176 "default: django-admin builtin commands succeed if settings are provided in the environment"177 args = ['sqlall','admin_scripts']178 out, err = self.run_django_admin(args,'settings')179 self.assertNoOutput(err)180 self.assertOutput(out, 'CREATE TABLE')181 def test_builtin_with_bad_settings(self):182 "default: django-admin builtin commands fail if settings file (from argument) doesn't exist"183 args = ['sqlall','--settings=bad_settings', 'admin_scripts']184 out, err = self.run_django_admin(args)185 self.assertNoOutput(out)186 self.assertOutput(err, "Could not import settings 'bad_settings'")187 def test_builtin_with_bad_environment(self):188 "default: django-admin builtin commands fail if settings file (from environment) doesn't exist"189 args = ['sqlall','admin_scripts']190 out, err = self.run_django_admin(args,'bad_settings')191 self.assertNoOutput(out)192 self.assertOutput(err, "Could not import settings 'bad_settings'")193 def test_custom_command(self):194 "default: django-admin can't execute user commands if it isn't provided settings"195 args = ['noargs_command']196 out, err = self.run_django_admin(args)197 self.assertNoOutput(out)198 self.assertOutput(err, "Unknown command: 'noargs_command'")199 def test_custom_command_with_settings(self):200 "default: django-admin can execute user commands if settings are provided as argument"201 args = ['noargs_command', '--settings=settings']202 out, err = self.run_django_admin(args)203 self.assertNoOutput(err)204 self.assertOutput(out, "EXECUTE:NoArgsCommand")205 def test_custom_command_with_environment(self):206 "default: django-admin can execute user commands if settings are provided in environment"207 args = ['noargs_command']208 out, err = self.run_django_admin(args,'settings')209 self.assertNoOutput(err)210 self.assertOutput(out, "EXECUTE:NoArgsCommand")211class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):212 """A series of tests for django-admin.py when using a settings.py file that213 contains the test application specified using a full path.214 """215 def setUp(self):216 self.write_settings('settings.py', ['django.contrib.auth', 'django.contrib.contenttypes', 'regressiontests.admin_scripts'])217 def tearDown(self):218 self.remove_settings('settings.py')219 def test_builtin_command(self):220 "fulldefault: django-admin builtin commands fail with an import error when no settings provided"221 args = ['sqlall','admin_scripts']222 out, err = self.run_django_admin(args)223 self.assertNoOutput(out)224 self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')225 def test_builtin_with_settings(self):226 "fulldefault: django-admin builtin commands succeed if a settings file is provided"227 args = ['sqlall','--settings=settings', 'admin_scripts']228 out, err = self.run_django_admin(args)229 self.assertNoOutput(err)230 self.assertOutput(out, 'CREATE TABLE')231 def test_builtin_with_environment(self):232 "fulldefault: django-admin builtin commands succeed if the environment contains settings"233 args = ['sqlall','admin_scripts']234 out, err = self.run_django_admin(args,'settings')235 self.assertNoOutput(err)236 self.assertOutput(out, 'CREATE TABLE')237 def test_builtin_with_bad_settings(self):238 "fulldefault: django-admin builtin commands fail if settings file (from argument) doesn't exist"239 args = ['sqlall','--settings=bad_settings', 'admin_scripts']240 out, err = self.run_django_admin(args)241 self.assertNoOutput(out)242 self.assertOutput(err, "Could not import settings 'bad_settings'")243 def test_builtin_with_bad_environment(self):244 "fulldefault: django-admin builtin commands fail if settings file (from environment) doesn't exist"245 args = ['sqlall','admin_scripts']246 out, err = self.run_django_admin(args,'bad_settings')247 self.assertNoOutput(out)248 self.assertOutput(err, "Could not import settings 'bad_settings'")249 def test_custom_command(self):250 "fulldefault: django-admin can't execute user commands unless settings are provided"251 args = ['noargs_command']252 out, err = self.run_django_admin(args)253 self.assertNoOutput(out)254 self.assertOutput(err, "Unknown command: 'noargs_command'")255 def test_custom_command_with_settings(self):256 "fulldefault: django-admin can execute user commands if settings are provided as argument"257 args = ['noargs_command', '--settings=settings']258 out, err = self.run_django_admin(args)259 self.assertNoOutput(err)260 self.assertOutput(out, "EXECUTE:NoArgsCommand")261 def test_custom_command_with_environment(self):262 "fulldefault: django-admin can execute user commands if settings are provided in environment"263 args = ['noargs_command']264 out, err = self.run_django_admin(args,'settings')265 self.assertNoOutput(err)266 self.assertOutput(out, "EXECUTE:NoArgsCommand")267class DjangoAdminMinimalSettings(AdminScriptTestCase):268 """A series of tests for django-admin.py when using a settings.py file that269 doesn't contain the test application.270 """271 def setUp(self):272 self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])273 def tearDown(self):274 self.remove_settings('settings.py')275 def test_builtin_command(self):276 "minimal: django-admin builtin commands fail with an import error when no settings provided"277 args = ['sqlall','admin_scripts']278 out, err = self.run_django_admin(args)279 self.assertNoOutput(out)280 self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')281 def test_builtin_with_settings(self):282 "minimal: django-admin builtin commands fail if settings are provided as argument"283 args = ['sqlall','--settings=settings', 'admin_scripts']284 out, err = self.run_django_admin(args)285 self.assertNoOutput(out)286 self.assertOutput(err, 'App with label admin_scripts could not be found')287 def test_builtin_with_environment(self):288 "minimal: django-admin builtin commands fail if settings are provided in the environment"289 args = ['sqlall','admin_scripts']290 out, err = self.run_django_admin(args,'settings')291 self.assertNoOutput(out)292 self.assertOutput(err, 'App with label admin_scripts could not be found')293 def test_builtin_with_bad_settings(self):294 "minimal: django-admin builtin commands fail if settings file (from argument) doesn't exist"295 args = ['sqlall','--settings=bad_settings', 'admin_scripts']296 out, err = self.run_django_admin(args)297 self.assertNoOutput(out)298 self.assertOutput(err, "Could not import settings 'bad_settings'")299 def test_builtin_with_bad_environment(self):300 "minimal: django-admin builtin commands fail if settings file (from environment) doesn't exist"301 args = ['sqlall','admin_scripts']302 out, err = self.run_django_admin(args,'bad_settings')303 self.assertNoOutput(out)304 self.assertOutput(err, "Could not import settings 'bad_settings'")305 def test_custom_command(self):306 "minimal: django-admin can't execute user commands unless settings are provided"307 args = ['noargs_command']308 out, err = self.run_django_admin(args)309 self.assertNoOutput(out)310 self.assertOutput(err, "Unknown command: 'noargs_command'")311 def test_custom_command_with_settings(self):312 "minimal: django-admin can't execute user commands, even if settings are provided as argument"313 args = ['noargs_command', '--settings=settings']314 out, err = self.run_django_admin(args)315 self.assertNoOutput(out)316 self.assertOutput(err, "Unknown command: 'noargs_command'")317 def test_custom_command_with_environment(self):318 "minimal: django-admin can't execute user commands, even if settings are provided in environment"319 args = ['noargs_command']320 out, err = self.run_django_admin(args,'settings')321 self.assertNoOutput(out)322 self.assertOutput(err, "Unknown command: 'noargs_command'")323class DjangoAdminAlternateSettings(AdminScriptTestCase):324 """A series of tests for django-admin.py when using a settings file325 with a name other than 'settings.py'.326 """327 def setUp(self):328 self.write_settings('alternate_settings.py')329 def tearDown(self):330 self.remove_settings('alternate_settings.py')331 def test_builtin_command(self):332 "alternate: django-admin builtin commands fail with an import error when no settings provided"333 args = ['sqlall','admin_scripts']334 out, err = self.run_django_admin(args)335 self.assertNoOutput(out)336 self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')337 def test_builtin_with_settings(self):338 "alternate: django-admin builtin commands succeed if settings are provided as argument"339 args = ['sqlall','--settings=alternate_settings', 'admin_scripts']340 out, err = self.run_django_admin(args)341 self.assertNoOutput(err)342 self.assertOutput(out, 'CREATE TABLE')343 def test_builtin_with_environment(self):344 "alternate: django-admin builtin commands succeed if settings are provided in the environment"345 args = ['sqlall','admin_scripts']346 out, err = self.run_django_admin(args,'alternate_settings')347 self.assertNoOutput(err)348 self.assertOutput(out, 'CREATE TABLE')349 def test_builtin_with_bad_settings(self):350 "alternate: django-admin builtin commands fail if settings file (from argument) doesn't exist"351 args = ['sqlall','--settings=bad_settings', 'admin_scripts']352 out, err = self.run_django_admin(args)353 self.assertNoOutput(out)354 self.assertOutput(err, "Could not import settings 'bad_settings'")355 def test_builtin_with_bad_environment(self):356 "alternate: django-admin builtin commands fail if settings file (from environment) doesn't exist"357 args = ['sqlall','admin_scripts']358 out, err = self.run_django_admin(args,'bad_settings')359 self.assertNoOutput(out)360 self.assertOutput(err, "Could not import settings 'bad_settings'")361 def test_custom_command(self):362 "alternate: django-admin can't execute user commands unless settings are provided"363 args = ['noargs_command']364 out, err = self.run_django_admin(args)365 self.assertNoOutput(out)366 self.assertOutput(err, "Unknown command: 'noargs_command'")367 def test_custom_command_with_settings(self):368 "alternate: django-admin can execute user commands if settings are provided as argument"369 args = ['noargs_command', '--settings=alternate_settings']370 out, err = self.run_django_admin(args)371 self.assertNoOutput(err)372 self.assertOutput(out, "EXECUTE:NoArgsCommand")373 def test_custom_command_with_environment(self):374 "alternate: django-admin can execute user commands if settings are provided in environment"375 args = ['noargs_command']376 out, err = self.run_django_admin(args,'alternate_settings')377 self.assertNoOutput(err)378 self.assertOutput(out, "EXECUTE:NoArgsCommand")379class DjangoAdminMultipleSettings(AdminScriptTestCase):380 """A series of tests for django-admin.py when multiple settings files381 (including the default 'settings.py') are available. The default settings382 file is insufficient for performing the operations described, so the383 alternate settings must be used by the running script.384 """385 def setUp(self):386 self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])387 self.write_settings('alternate_settings.py')388 def tearDown(self):389 self.remove_settings('settings.py')390 self.remove_settings('alternate_settings.py')391 def test_builtin_command(self):392 "alternate: django-admin builtin commands fail with an import error when no settings provided"393 args = ['sqlall','admin_scripts']394 out, err = self.run_django_admin(args)395 self.assertNoOutput(out)396 self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')397 def test_builtin_with_settings(self):398 "alternate: django-admin builtin commands succeed if settings are provided as argument"399 args = ['sqlall','--settings=alternate_settings', 'admin_scripts']400 out, err = self.run_django_admin(args)401 self.assertNoOutput(err)402 self.assertOutput(out, 'CREATE TABLE')403 def test_builtin_with_environment(self):404 "alternate: django-admin builtin commands succeed if settings are provided in the environment"405 args = ['sqlall','admin_scripts']406 out, err = self.run_django_admin(args,'alternate_settings')407 self.assertNoOutput(err)408 self.assertOutput(out, 'CREATE TABLE')409 def test_builtin_with_bad_settings(self):410 "alternate: django-admin builtin commands fail if settings file (from argument) doesn't exist"411 args = ['sqlall','--settings=bad_settings', 'admin_scripts']412 out, err = self.run_django_admin(args)413 self.assertOutput(err, "Could not import settings 'bad_settings'")414 def test_builtin_with_bad_environment(self):415 "alternate: django-admin builtin commands fail if settings file (from environment) doesn't exist"416 args = ['sqlall','admin_scripts']417 out, err = self.run_django_admin(args,'bad_settings')418 self.assertNoOutput(out)419 self.assertOutput(err, "Could not import settings 'bad_settings'")420 def test_custom_command(self):421 "alternate: django-admin can't execute user commands unless settings are provided"422 args = ['noargs_command']423 out, err = self.run_django_admin(args)424 self.assertNoOutput(out)425 self.assertOutput(err, "Unknown command: 'noargs_command'")426 def test_custom_command_with_settings(self):427 "alternate: django-admin can't execute user commands, even if settings are provided as argument"428 args = ['noargs_command', '--settings=alternate_settings']429 out, err = self.run_django_admin(args)430 self.assertNoOutput(err)431 self.assertOutput(out, "EXECUTE:NoArgsCommand")432 def test_custom_command_with_environment(self):433 "alternate: django-admin can't execute user commands, even if settings are provided in environment"434 args = ['noargs_command']435 out, err = self.run_django_admin(args,'alternate_settings')436 self.assertNoOutput(err)437 self.assertOutput(out, "EXECUTE:NoArgsCommand")438class DjangoAdminSettingsDirectory(AdminScriptTestCase):439 """440 A series of tests for django-admin.py when the settings file is in a441 directory. (see #9751).442 """443 444 def setUp(self):445 self.write_settings('settings', is_dir=True)446 def tearDown(self):447 self.remove_settings('settings', is_dir=True)448 def test_setup_environ(self):449 "directory: startapp creates the correct directory"450 test_dir = os.path.dirname(os.path.dirname(__file__))451 args = ['startapp','settings_test']452 out, err = self.run_django_admin(args,'settings')453 self.assertNoOutput(err)454 self.assert_(os.path.exists(os.path.join(test_dir, 'settings_test')))455 shutil.rmtree(os.path.join(test_dir, 'settings_test'))456 def test_builtin_command(self):457 "directory: django-admin builtin commands fail with an import error when no settings provided"458 args = ['sqlall','admin_scripts']459 out, err = self.run_django_admin(args)460 self.assertNoOutput(out)461 self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')462 def test_builtin_with_bad_settings(self):463 "directory: django-admin builtin commands fail if settings file (from argument) doesn't exist"464 args = ['sqlall','--settings=bad_settings', 'admin_scripts']465 out, err = self.run_django_admin(args)466 self.assertOutput(err, "Could not import settings 'bad_settings'")467 def test_builtin_with_bad_environment(self):468 "directory: django-admin builtin commands fail if settings file (from environment) doesn't exist"469 args = ['sqlall','admin_scripts']470 out, err = self.run_django_admin(args,'bad_settings')471 self.assertNoOutput(out)472 self.assertOutput(err, "Could not import settings 'bad_settings'")473 def test_custom_command(self):474 "directory: django-admin can't execute user commands unless settings are provided"475 args = ['noargs_command']476 out, err = self.run_django_admin(args)477 self.assertNoOutput(out)478 self.assertOutput(err, "Unknown command: 'noargs_command'")479 def test_builtin_with_settings(self):480 "directory: django-admin builtin commands succeed if settings are provided as argument"481 args = ['sqlall','--settings=settings', 'admin_scripts']482 out, err = self.run_django_admin(args)483 self.assertNoOutput(err)484 self.assertOutput(out, 'CREATE TABLE')485 def test_builtin_with_environment(self):486 "directory: django-admin builtin commands succeed if settings are provided in the environment"487 args = ['sqlall','admin_scripts']488 out, err = self.run_django_admin(args,'settings')489 self.assertNoOutput(err)490 self.assertOutput(out, 'CREATE TABLE')491##########################################################################492# MANAGE.PY TESTS493# This next series of test classes checks the environment processing494# of the generated manage.py script495##########################################################################496class ManageNoSettings(AdminScriptTestCase):497 "A series of tests for manage.py when there is no settings.py file."498 def test_builtin_command(self):499 "no settings: manage.py builtin commands fail with an import error when no settings provided"500 args = ['sqlall','admin_scripts']501 out, err = self.run_manage(args)502 self.assertNoOutput(out)503 self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")504 def test_builtin_with_bad_settings(self):505 "no settings: manage.py builtin commands fail if settings file (from argument) doesn't exist"506 args = ['sqlall','--settings=bad_settings', 'admin_scripts']507 out, err = self.run_manage(args)508 self.assertNoOutput(out)509 self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")510 def test_builtin_with_bad_environment(self):511 "no settings: manage.py builtin commands fail if settings file (from environment) doesn't exist"512 args = ['sqlall','admin_scripts']513 out, err = self.run_manage(args,'bad_settings')514 self.assertNoOutput(out)515 self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")516class ManageDefaultSettings(AdminScriptTestCase):517 """A series of tests for manage.py when using a settings.py file that518 contains the test application.519 """520 def setUp(self):521 self.write_settings('settings.py')522 def tearDown(self):523 self.remove_settings('settings.py')524 def test_builtin_command(self):525 "default: manage.py builtin commands succeed when default settings are appropriate"526 args = ['sqlall','admin_scripts']527 out, err = self.run_manage(args)528 self.assertNoOutput(err)529 self.assertOutput(out, 'CREATE TABLE')530 def test_builtin_with_settings(self):531 "default: manage.py builtin commands succeed if settings are provided as argument"532 args = ['sqlall','--settings=settings', 'admin_scripts']533 out, err = self.run_manage(args)534 self.assertNoOutput(err)535 self.assertOutput(out, 'CREATE TABLE')536 def test_builtin_with_environment(self):537 "default: manage.py builtin commands succeed if settings are provided in the environment"538 args = ['sqlall','admin_scripts']539 out, err = self.run_manage(args,'settings')540 self.assertNoOutput(err)541 self.assertOutput(out, 'CREATE TABLE')542 def test_builtin_with_bad_settings(self):543 "default: manage.py builtin commands succeed if settings file (from argument) doesn't exist"544 args = ['sqlall','--settings=bad_settings', 'admin_scripts']545 out, err = self.run_manage(args)546 self.assertNoOutput(out)547 self.assertOutput(err, "Could not import settings 'bad_settings'")548 def test_builtin_with_bad_environment(self):549 "default: manage.py builtin commands fail if settings file (from environment) doesn't exist"550 args = ['sqlall','admin_scripts']551 out, err = self.run_manage(args,'bad_settings')552 self.assertNoOutput(err)553 self.assertOutput(out, 'CREATE TABLE')554 def test_custom_command(self):555 "default: manage.py can execute user commands when default settings are appropriate"556 args = ['noargs_command']557 out, err = self.run_manage(args)558 self.assertNoOutput(err)559 self.assertOutput(out, "EXECUTE:NoArgsCommand")560 def test_custom_command_with_settings(self):561 "default: manage.py can execute user commands when settings are provided as argument"562 args = ['noargs_command', '--settings=settings']563 out, err = self.run_manage(args)564 self.assertNoOutput(err)565 self.assertOutput(out, "EXECUTE:NoArgsCommand")566 def test_custom_command_with_environment(self):567 "default: manage.py can execute user commands when settings are provided in environment"568 args = ['noargs_command']569 out, err = self.run_manage(args,'settings')570 self.assertNoOutput(err)571 self.assertOutput(out, "EXECUTE:NoArgsCommand")572class ManageFullPathDefaultSettings(AdminScriptTestCase):573 """A series of tests for manage.py when using a settings.py file that574 contains the test application specified using a full path.575 """576 def setUp(self):577 self.write_settings('settings.py', ['django.contrib.auth', 'django.contrib.contenttypes', 'regressiontests.admin_scripts'])578 def tearDown(self):579 self.remove_settings('settings.py')580 def test_builtin_command(self):581 "fulldefault: manage.py builtin commands succeed when default settings are appropriate"582 args = ['sqlall','admin_scripts']583 out, err = self.run_manage(args)584 self.assertNoOutput(err)585 self.assertOutput(out, 'CREATE TABLE')586 def test_builtin_with_settings(self):587 "fulldefault: manage.py builtin commands succeed if settings are provided as argument"588 args = ['sqlall','--settings=settings', 'admin_scripts']589 out, err = self.run_manage(args)590 self.assertNoOutput(err)591 self.assertOutput(out, 'CREATE TABLE')592 def test_builtin_with_environment(self):593 "fulldefault: manage.py builtin commands succeed if settings are provided in the environment"594 args = ['sqlall','admin_scripts']595 out, err = self.run_manage(args,'settings')596 self.assertNoOutput(err)597 self.assertOutput(out, 'CREATE TABLE')598 def test_builtin_with_bad_settings(self):599 "fulldefault: manage.py builtin commands succeed if settings file (from argument) doesn't exist"600 args = ['sqlall','--settings=bad_settings', 'admin_scripts']601 out, err = self.run_manage(args)602 self.assertNoOutput(out)603 self.assertOutput(err, "Could not import settings 'bad_settings'")604 def test_builtin_with_bad_environment(self):605 "fulldefault: manage.py builtin commands fail if settings file (from environment) doesn't exist"606 args = ['sqlall','admin_scripts']607 out, err = self.run_manage(args,'bad_settings')608 self.assertNoOutput(err)609 self.assertOutput(out, 'CREATE TABLE')610 def test_custom_command(self):611 "fulldefault: manage.py can execute user commands when default settings are appropriate"612 args = ['noargs_command']613 out, err = self.run_manage(args)614 self.assertNoOutput(err)615 self.assertOutput(out, "EXECUTE:NoArgsCommand")616 def test_custom_command_with_settings(self):617 "fulldefault: manage.py can execute user commands when settings are provided as argument"618 args = ['noargs_command', '--settings=settings']619 out, err = self.run_manage(args)620 self.assertNoOutput(err)621 self.assertOutput(out, "EXECUTE:NoArgsCommand")622 def test_custom_command_with_environment(self):623 "fulldefault: manage.py can execute user commands when settings are provided in environment"624 args = ['noargs_command']625 out, err = self.run_manage(args,'settings')626 self.assertNoOutput(err)627 self.assertOutput(out, "EXECUTE:NoArgsCommand")628class ManageMinimalSettings(AdminScriptTestCase):629 """A series of tests for manage.py when using a settings.py file that630 doesn't contain the test application.631 """632 def setUp(self):633 self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])634 def tearDown(self):635 self.remove_settings('settings.py')636 def test_builtin_command(self):637 "minimal: manage.py builtin commands fail with an import error when no settings provided"638 args = ['sqlall','admin_scripts']639 out, err = self.run_manage(args)640 self.assertNoOutput(out)641 self.assertOutput(err, 'App with label admin_scripts could not be found')642 def test_builtin_with_settings(self):643 "minimal: manage.py builtin commands fail if settings are provided as argument"644 args = ['sqlall','--settings=settings', 'admin_scripts']645 out, err = self.run_manage(args)646 self.assertNoOutput(out)647 self.assertOutput(err, 'App with label admin_scripts could not be found')648 def test_builtin_with_environment(self):649 "minimal: manage.py builtin commands fail if settings are provided in the environment"650 args = ['sqlall','admin_scripts']651 out, err = self.run_manage(args,'settings')652 self.assertNoOutput(out)653 self.assertOutput(err, 'App with label admin_scripts could not be found')654 def test_builtin_with_bad_settings(self):655 "minimal: manage.py builtin commands fail if settings file (from argument) doesn't exist"656 args = ['sqlall','--settings=bad_settings', 'admin_scripts']657 out, err = self.run_manage(args)658 self.assertNoOutput(out)659 self.assertOutput(err, "Could not import settings 'bad_settings'")660 def test_builtin_with_bad_environment(self):661 "minimal: manage.py builtin commands fail if settings file (from environment) doesn't exist"662 args = ['sqlall','admin_scripts']663 out, err = self.run_manage(args,'bad_settings')664 self.assertNoOutput(out)665 self.assertOutput(err, 'App with label admin_scripts could not be found')666 def test_custom_command(self):667 "minimal: manage.py can't execute user commands without appropriate settings"668 args = ['noargs_command']669 out, err = self.run_manage(args)670 self.assertNoOutput(out)671 self.assertOutput(err, "Unknown command: 'noargs_command'")672 def test_custom_command_with_settings(self):673 "minimal: manage.py can't execute user commands, even if settings are provided as argument"674 args = ['noargs_command', '--settings=settings']675 out, err = self.run_manage(args)676 self.assertNoOutput(out)677 self.assertOutput(err, "Unknown command: 'noargs_command'")678 def test_custom_command_with_environment(self):679 "minimal: manage.py can't execute user commands, even if settings are provided in environment"680 args = ['noargs_command']681 out, err = self.run_manage(args,'settings')682 self.assertNoOutput(out)683 self.assertOutput(err, "Unknown command: 'noargs_command'")684class ManageAlternateSettings(AdminScriptTestCase):685 """A series of tests for manage.py when using a settings file686 with a name other than 'settings.py'.687 """688 def setUp(self):689 self.write_settings('alternate_settings.py')690 def tearDown(self):691 self.remove_settings('alternate_settings.py')692 def test_builtin_command(self):693 "alternate: manage.py builtin commands fail with an import error when no default settings provided"694 args = ['sqlall','admin_scripts']695 out, err = self.run_manage(args)696 self.assertNoOutput(out)697 self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")698 def test_builtin_with_settings(self):699 "alternate: manage.py builtin commands fail if settings are provided as argument but no defaults"700 args = ['sqlall','--settings=alternate_settings', 'admin_scripts']701 out, err = self.run_manage(args)702 self.assertNoOutput(out)703 self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")704 def test_builtin_with_environment(self):705 "alternate: manage.py builtin commands fail if settings are provided in the environment but no defaults"706 args = ['sqlall','admin_scripts']707 out, err = self.run_manage(args,'alternate_settings')708 self.assertNoOutput(out)709 self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")710 def test_builtin_with_bad_settings(self):711 "alternate: manage.py builtin commands fail if settings file (from argument) doesn't exist"712 args = ['sqlall','--settings=bad_settings', 'admin_scripts']713 out, err = self.run_manage(args)714 self.assertNoOutput(out)715 self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")716 def test_builtin_with_bad_environment(self):717 "alternate: manage.py builtin commands fail if settings file (from environment) doesn't exist"718 args = ['sqlall','admin_scripts']719 out, err = self.run_manage(args,'bad_settings')720 self.assertNoOutput(out)721 self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")722 def test_custom_command(self):723 "alternate: manage.py can't execute user commands"724 args = ['noargs_command']725 out, err = self.run_manage(args)726 self.assertNoOutput(out)727 self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")728 def test_custom_command_with_settings(self):729 "alternate: manage.py can't execute user commands, even if settings are provided as argument"730 args = ['noargs_command', '--settings=alternate_settings']731 out, err = self.run_manage(args)732 self.assertNoOutput(out)733 self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")734 def test_custom_command_with_environment(self):735 "alternate: manage.py can't execute user commands, even if settings are provided in environment"736 args = ['noargs_command']737 out, err = self.run_manage(args,'alternate_settings')738 self.assertNoOutput(out)739 self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")740class ManageMultipleSettings(AdminScriptTestCase):741 """A series of tests for manage.py when multiple settings files742 (including the default 'settings.py') are available. The default settings743 file is insufficient for performing the operations described, so the744 alternate settings must be used by the running script.745 """746 def setUp(self):747 self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])748 self.write_settings('alternate_settings.py')749 def tearDown(self):750 self.remove_settings('settings.py')751 self.remove_settings('alternate_settings.py')752 def test_builtin_command(self):753 "multiple: manage.py builtin commands fail with an import error when no settings provided"754 args = ['sqlall','admin_scripts']755 out, err = self.run_manage(args)756 self.assertNoOutput(out)757 self.assertOutput(err, 'App with label admin_scripts could not be found.')758 def test_builtin_with_settings(self):759 "multiple: manage.py builtin commands succeed if settings are provided as argument"760 args = ['sqlall','--settings=alternate_settings', 'admin_scripts']761 out, err = self.run_manage(args)762 self.assertNoOutput(err)763 self.assertOutput(out, 'CREATE TABLE')764 def test_builtin_with_environment(self):765 "multiple: manage.py builtin commands fail if settings are provided in the environment"766 # FIXME: This doesn't seem to be the correct output.767 args = ['sqlall','admin_scripts']768 out, err = self.run_manage(args,'alternate_settings')769 self.assertNoOutput(out)770 self.assertOutput(err, 'App with label admin_scripts could not be found.')771 def test_builtin_with_bad_settings(self):772 "multiple: manage.py builtin commands fail if settings file (from argument) doesn't exist"773 args = ['sqlall','--settings=bad_settings', 'admin_scripts']774 out, err = self.run_manage(args)775 self.assertNoOutput(out)776 self.assertOutput(err, "Could not import settings 'bad_settings'")777 def test_builtin_with_bad_environment(self):778 "multiple: manage.py builtin commands fail if settings file (from environment) doesn't exist"779 args = ['sqlall','admin_scripts']780 out, err = self.run_manage(args,'bad_settings')781 self.assertNoOutput(out)782 self.assertOutput(err, "App with label admin_scripts could not be found")783 def test_custom_command(self):784 "multiple: manage.py can't execute user commands using default settings"785 args = ['noargs_command']786 out, err = self.run_manage(args)787 self.assertNoOutput(out)788 self.assertOutput(err, "Unknown command: 'noargs_command'")789 def test_custom_command_with_settings(self):790 "multiple: manage.py can execute user commands if settings are provided as argument"791 args = ['noargs_command', '--settings=alternate_settings']792 out, err = self.run_manage(args)793 self.assertNoOutput(err)794 self.assertOutput(out, "EXECUTE:NoArgsCommand")795 def test_custom_command_with_environment(self):796 "multiple: manage.py can execute user commands if settings are provided in environment"797 args = ['noargs_command']798 out, err = self.run_manage(args,'alternate_settings')799 self.assertNoOutput(out)800 self.assertOutput(err, "Unknown command: 'noargs_command'")801##########################################################################802# COMMAND PROCESSING TESTS803# Check that user-space commands are correctly handled - in particular,804# that arguments to the commands are correctly parsed and processed.805##########################################################################806class CommandTypes(AdminScriptTestCase):807 "Tests for the various types of base command types that can be defined."808 def setUp(self):809 self.write_settings('settings.py')810 def tearDown(self):811 self.remove_settings('settings.py')812 def test_version(self):813 "--version is handled as a special case"814 args = ['--version']815 out, err = self.run_manage(args)816 self.assertNoOutput(err)817 # Only check the first part of the version number818 self.assertOutput(out, get_version().split('-')[0])819 def test_help(self):820 "--help is handled as a special case"821 args = ['--help']822 out, err = self.run_manage(args)823 if sys.version_info < (2, 5):824 self.assertOutput(out, "usage: manage.py subcommand [options] [args]")825 else:826 self.assertOutput(out, "Usage: manage.py subcommand [options] [args]")827 self.assertOutput(err, "Type 'manage.py help <subcommand>' for help on a specific subcommand.")828 def test_specific_help(self):829 "--help can be used on a specific command"830 args = ['sqlall','--help']831 out, err = self.run_manage(args)832 self.assertNoOutput(err)833 self.assertOutput(out, "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).")834 def test_base_command(self):835 "User BaseCommands can execute when a label is provided"836 args = ['base_command','testlabel']837 out, err = self.run_manage(args)838 self.assertNoOutput(err)839 self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")840 def test_base_command_no_label(self):841 "User BaseCommands can execute when no labels are provided"842 args = ['base_command']843 out, err = self.run_manage(args)844 self.assertNoOutput(err)845 self.assertOutput(out, "EXECUTE:BaseCommand labels=(), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")846 def test_base_command_multiple_label(self):847 "User BaseCommands can execute when no labels are provided"848 args = ['base_command','testlabel','anotherlabel']849 out, err = self.run_manage(args)850 self.assertNoOutput(err)851 self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel', 'anotherlabel'), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")852 def test_base_command_with_option(self):853 "User BaseCommands can execute with options when a label is provided"854 args = ['base_command','testlabel','--option_a=x']855 out, err = self.run_manage(args)856 self.assertNoOutput(err)857 self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")858 def test_base_command_with_options(self):859 "User BaseCommands can execute with multiple options when a label is provided"860 args = ['base_command','testlabel','-a','x','--option_b=y']861 out, err = self.run_manage(args)862 self.assertNoOutput(err)863 self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")864 def test_noargs(self):865 "NoArg Commands can be executed"866 args = ['noargs_command']867 out, err = self.run_manage(args)868 self.assertNoOutput(err)869 self.assertOutput(out, "EXECUTE:NoArgsCommand options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")870 def test_noargs_with_args(self):871 "NoArg Commands raise an error if an argument is provided"872 args = ['noargs_command','argument']873 out, err = self.run_manage(args)874 self.assertOutput(err, "Error: Command doesn't accept any arguments")875 def test_app_command(self):876 "User AppCommands can execute when a single app name is provided"877 args = ['app_command', 'auth']878 out, err = self.run_manage(args)879 self.assertNoOutput(err)880 self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.auth.models'")881 self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py']))882 self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")883 def test_app_command_no_apps(self):884 "User AppCommands raise an error when no app name is provided"885 args = ['app_command']886 out, err = self.run_manage(args)887 self.assertOutput(err, 'Error: Enter at least one appname.')888 def test_app_command_multiple_apps(self):889 "User AppCommands raise an error when multiple app names are provided"890 args = ['app_command','auth','contenttypes']891 out, err = self.run_manage(args)892 self.assertNoOutput(err)893 self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.auth.models'")894 self.assertOutput(out, os.sep.join(['django','contrib','auth','models.py']))895 self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")896 self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.contenttypes.models'")897 self.assertOutput(out, os.sep.join(['django','contrib','contenttypes','models.py']))898 self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")899 def test_app_command_invalid_appname(self):900 "User AppCommands can execute when a single app name is provided"901 args = ['app_command', 'NOT_AN_APP']902 out, err = self.run_manage(args)903 self.assertOutput(err, "App with label NOT_AN_APP could not be found")904 def test_app_command_some_invalid_appnames(self):905 "User AppCommands can execute when some of the provided app names are invalid"906 args = ['app_command', 'auth', 'NOT_AN_APP']907 out, err = self.run_manage(args)908 self.assertOutput(err, "App with label NOT_AN_APP could not be found")909 def test_label_command(self):910 "User LabelCommands can execute when a label is provided"911 args = ['label_command','testlabel']912 out, err = self.run_manage(args)913 self.assertNoOutput(err)914 self.assertOutput(out, "EXECUTE:LabelCommand label=testlabel, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")915 def test_label_command_no_label(self):916 "User LabelCommands raise an error if no label is provided"917 args = ['label_command']918 out, err = self.run_manage(args)919 self.assertOutput(err, 'Enter at least one label')920 def test_label_command_multiple_label(self):921 "User LabelCommands are executed multiple times if multiple labels are provided"922 args = ['label_command','testlabel','anotherlabel']923 out, err = self.run_manage(args)924 self.assertNoOutput(err)925 self.assertOutput(out, "EXECUTE:LabelCommand label=testlabel, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")926 self.assertOutput(out, "EXECUTE:LabelCommand label=anotherlabel, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")927class ArgumentOrder(AdminScriptTestCase):928 """Tests for 2-stage argument parsing scheme.929 django-admin command arguments are parsed in 2 parts; the core arguments930 (--settings, --traceback and --pythonpath) are parsed using a Lax parser.931 This Lax parser ignores any unknown options. Then the full settings are932 passed to the command parser, which extracts commands of interest to the933 individual command.934 """935 def setUp(self):936 self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])937 self.write_settings('alternate_settings.py')938 def tearDown(self):939 self.remove_settings('settings.py')940 self.remove_settings('alternate_settings.py')941 def test_setting_then_option(self):942 "Options passed after settings are correctly handled"943 args = ['base_command','testlabel','--settings=alternate_settings','--option_a=x']944 out, err = self.run_manage(args)945 self.assertNoOutput(err)946 self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")947 def test_setting_then_short_option(self):948 "Short options passed after settings are correctly handled"949 args = ['base_command','testlabel','--settings=alternate_settings','--option_a=x']950 out, err = self.run_manage(args)951 self.assertNoOutput(err)952 self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")953 def test_option_then_setting(self):954 "Options passed before settings are correctly handled"955 args = ['base_command','testlabel','--option_a=x','--settings=alternate_settings']956 out, err = self.run_manage(args)957 self.assertNoOutput(err)958 self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")959 def test_short_option_then_setting(self):960 "Short options passed before settings are correctly handled"961 args = ['base_command','testlabel','-a','x','--settings=alternate_settings']962 out, err = self.run_manage(args)963 self.assertNoOutput(err)964 self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")965 def test_option_then_setting_then_option(self):966 "Options are correctly handled when they are passed before and after a setting"967 args = ['base_command','testlabel','--option_a=x','--settings=alternate_settings','--option_b=y']968 out, err = self.run_manage(args)969 self.assertNoOutput(err)...

Full Screen

Full Screen

test_scripts.py

Source:test_scripts.py Github

copy

Full Screen

...21class BaseTest(unittest.TestCase):22 """23 Base for test classes24 """25 def assertOutput(self, options, output_file, input_file=None):26 if not input_file:27 input_file = self.input_file28 self.assertTrue(29 try_script(30 self.function,31 options,32 input_file,33 expected_output_file = output_file34 )35 )36 def assertExitStatus(self, options, exit_status=hxl.scripts.EXIT_OK, input_file=None):37 if not input_file:38 input_file = self.input_file39 self.assertTrue(40 try_script(41 self.function,42 options,43 input_file,44 expected_exit_status = exit_status45 )46 )47class TestAdd(BaseTest):48 """49 Test the hxladd command-line tool.50 """51 def setUp(self):52 self.function = hxl.scripts.hxladd_main53 self.input_file = 'input-simple.csv'54 def test_default(self):55 self.assertOutput(['-s', 'date+reported=2015-03-31'], 'add-output-default.csv')56 self.assertOutput(['--spec', 'date+reported=2015-03-31'], 'add-output-default.csv')57 def test_headers(self):58 self.assertOutput(['-s', 'Report Date#date+reported=2015-03-31'], 'add-output-headers.csv')59 self.assertOutput(['--spec', 'Report Date#date+reported=2015-03-31'], 'add-output-headers.csv')60 def test_before(self):61 self.assertOutput(['-b', '-s', 'date+reported=2015-03-31'], 'add-output-before.csv')62 self.assertOutput(['--before', '--spec', 'date+reported=2015-03-31'], 'add-output-before.csv')63 64class TestAppend(BaseTest):65 """ Test the hxlappend command-line tool. """66 def setUp(self):67 self.function = hxl.scripts.hxlappend_main68 self.input_file = 'input-simple.csv'69 def test_append(self):70 self.assertOutput(['-a', resolve_file('input-simple.csv')], 'append-dataset.csv')71 self.assertOutput(['--append', resolve_file('input-simple.csv')], 'append-dataset.csv')72class TestClean(BaseTest):73 """74 Test the hxlclean command-line tool.75 """76 def setUp(self):77 self.function = hxl.scripts.hxlclean_main78 self.input_file = 'input-simple.csv'79 def test_noheaders(self):80 self.assertOutput(['--remove-headers'], 'clean-output-noheaders.csv')81 def test_headers(self):82 self.assertOutput([], 'clean-output-headers.csv')83 def test_whitespace(self):84 self.assertOutput(['-w', 'subsector'], 'clean-output-whitespace-tags.csv', 'input-whitespace.csv')85 def test_case(self):86 self.assertOutput(['-u', 'sector,subsector'], 'clean-output-upper.csv')87 self.assertOutput(['-l', 'sector,subsector'], 'clean-output-lower.csv')88 # TODO: test dates and numbers89class TestCount(BaseTest):90 """91 Test the hxlcount command-line tool.92 """93 def setUp(self):94 self.function = hxl.scripts.hxlcount_main95 self.input_file = 'input-simple.csv'96 def test_simple(self):97 self.assertOutput(['-t', 'org,adm1'], 'count-output-simple.csv')98 self.assertOutput(['--tags', 'org,adm1'], 'count-output-simple.csv')99 def test_aggregated(self):100 self.assertOutput(['-t', 'org,adm1', '-a', 'sum(targeted) as Total targeted#targeted+total'], 'count-output-aggregated.csv')101 def test_count_colspec(self):102 self.assertOutput(['-t', 'org,adm1', '-a', 'count() as Activities#output+activities'], 'count-output-colspec.csv')103class TestCut(BaseTest):104 """105 Test the hxlcut command-line tool.106 """107 def setUp(self):108 self.function = hxl.scripts.hxlcut_main109 self.input_file = 'input-simple.csv'110 def test_includes(self):111 self.assertOutput(['-i', 'sector,org,adm1'], 'cut-output-includes.csv')112 self.assertOutput(['--include', 'sector,org,adm1'], 'cut-output-includes.csv')113 def test_excludes(self):114 self.assertOutput(['-x', 'population+sex,targeted'], 'cut-output-excludes.csv')115 self.assertOutput(['--exclude', 'population+sex,targeted'], 'cut-output-excludes.csv')116class TestMerge(BaseTest):117 """118 Test the hxlmerge command-line tool.119 """120 def setUp(self):121 self.function = hxl.scripts.hxlmerge_main122 self.input_file = 'input-simple.csv'123 def test_merge(self):124 self.assertOutput(['-k', 'sector', '-t', 'status', '-m', resolve_file('input-merge.csv')], 'merge-output-basic.csv')125 self.assertOutput(['--keys', 'sector', '--tags', 'status', '-m', resolve_file('input-merge.csv')], 'merge-output-basic.csv')126 def test_replace(self):127 self.input_file = 'input-status.csv'128 self.assertOutput(['-r', '-k', 'sector', '-t', 'status', '-m', resolve_file('input-merge.csv')], 'merge-output-replace.csv')129 self.assertOutput(['--replace', '-k', 'sector', '-t', 'status', '-m', resolve_file('input-merge.csv')], 'merge-output-replace.csv')130 def test_overwrite (self):131 self.input_file = 'input-status.csv'132 self.assertOutput(['-O', '-r', '-k', 'sector', '-t', 'status', '-m', resolve_file('input-merge.csv')], 'merge-output-overwrite.csv')133 self.assertOutput(['--overwrite', '--replace', '-k', 'sector', '-t', 'status', '-m', resolve_file('input-merge.csv')], 'merge-output-overwrite.csv')134class TestRename(BaseTest):135 """136 Test the hxlrename command-line tool.137 """138 def setUp(self):139 self.function = hxl.scripts.hxlrename_main140 self.input_file = 'input-simple.csv'141 def test_single(self):142 self.assertOutput(['-r', 'targeted:affected'], 'rename-output-single.csv')143 self.assertOutput(['--rename', 'targeted:affected'], 'rename-output-single.csv')144 def test_header(self):145 self.assertOutput(['-r', 'targeted:Affected#affected'], 'rename-output-header.csv')146 def test_multiple(self):147 self.assertOutput(['-r', 'targeted:affected', '-r', 'org:funding'], 'rename-output-multiple.csv')148class TestSelect(BaseTest):149 """150 Test the hxlselect command-line tool.151 """152 def setUp(self):153 self.function = hxl.scripts.hxlselect_main154 self.input_file = 'input-simple.csv'155 def test_eq(self):156 self.assertOutput(['-q', 'sector=WASH'], 'select-output-eq.csv')157 self.assertOutput(['--query', 'sector=WASH'], 'select-output-eq.csv')158 def test_ne(self):159 self.assertOutput(['-q', 'sector!=WASH'], 'select-output-ne.csv')160 def test_lt(self):161 self.assertOutput(['-q', 'targeted<200'], 'select-output-lt.csv')162 def test_le(self):163 self.assertOutput(['-q', 'targeted<=100'], 'select-output-le.csv')164 def test_gt(self):165 self.assertOutput(['-q', 'targeted>100'], 'select-output-gt.csv')166 def test_ge(self):167 self.assertOutput(['-q', 'targeted>=100'], 'select-output-ge.csv')168 def test_re(self):169 self.assertOutput(['-q', 'sector~^W..H'], 'select-output-re.csv')170 def test_nre(self):171 self.assertOutput(['-q', 'sector!~^W..H'], 'select-output-nre.csv')172 def test_reverse(self):173 self.assertOutput(['-r', '-q', 'sector=WASH'], 'select-output-reverse.csv')174 self.assertOutput(['--reverse', '--query', 'sector=WASH'], 'select-output-reverse.csv')175 def test_multiple(self):176 self.assertOutput(['-q', 'sector=WASH', '-q', 'sector=Salud'], 'select-output-multiple.csv')177class TestSort(BaseTest):178 """179 Test the hxlsort command-line tool,.180 """181 def setUp(self):182 self.function = hxl.scripts.hxlsort_main183 self.input_file = 'input-simple.csv'184 def test_default(self):185 self.assertOutput([], 'sort-output-default.csv')186 def test_tags(self):187 self.assertOutput(['-t', 'country'], 'sort-output-tags.csv')188 self.assertOutput(['--tags', 'country'], 'sort-output-tags.csv')189 def test_numeric(self):190 self.assertOutput(['-t', 'targeted'], 'sort-output-numeric.csv')191 def test_date(self):192 self.input_file = 'input-date.csv'193 self.assertOutput(['-t', 'date+reported'], 'sort-output-date.csv')194 def test_reverse(self):195 self.assertOutput(['-r'], 'sort-output-reverse.csv')196 self.assertOutput(['--reverse'], 'sort-output-reverse.csv')197class TestTag(BaseTest):198 """199 Test the hxltag command-line tool.200 """201 def setUp(self):202 self.function = hxl.scripts.hxltag_main203 self.input_file = 'input-untagged.csv'204 def test_full(self):205 """Use full header text for tagging."""206 self.assertOutput([207 '-m', 'Organisation#org',208 '-m', 'Cluster#sector',209 '-m', 'Country#country',210 '-m', 'Subdivision#adm1'211 ], 'tag-output-full.csv')212 def test_substrings(self):213 """Use header substrings for tagging."""214 self.assertOutput([215 '-m', 'org#org',216 '-m', 'cluster#sector',217 '-m', 'ntry#country',218 '-m', 'div#adm1'219 ], 'tag-output-full.csv')220 self.assertOutput([221 '-a', # force match_all222 '-m', 'org#org', # should fail223 '-m', 'cluster#sector' #should succeed224 ], 'tag-output-notsubstrings.csv')225 def test_partial(self):226 """Try tagging only one row."""227 self.assertOutput([228 '--map', 'cluster#sector'229 ], 'tag-output-partial.csv')230 def test_ambiguous(self):231 """Use an ambiguous header for the second one."""232 self.assertOutput([233 '-m', 'organisation#org',234 '-m', 'is#adm1'235 ], 'tag-output-ambiguous.csv')236 def test_default_tag(self):237 """Supply a default tag."""238 self.assertOutput([239 '-m', 'organisation#org',240 '-d', '#meta'241 ], 'tag-output-default.csv')242class TestValidate(BaseTest):243 """244 Test the hxltag command-line tool.245 """246 def setUp(self):247 self.function = hxl.scripts.hxlvalidate_main248 self.input_file = 'input-simple.csv'249 def test_default_valid_status(self):250 self.assertExitStatus([])251 def test_bad_hxl_status(self):252 self.input_file = 'input-untagged.csv'...

Full Screen

Full Screen

asdottysql.py

Source:asdottysql.py Github

copy

Full Screen

...26 pass27 def testExpression(self):28 """Get coverage test to shut up."""29 pass30 def assertOutput(self, original, output):31 q = query.Query(original)32 actual_output = asdottysql.asdottysql(q)33 self.assertEqual(output, actual_output)34 actual_root = query.Query(actual_output).root35 self.assertEqual(q.root, actual_root)36 def testLiteral(self):37 self.assertOutput(original="5", output="5")38 def testVar(self):39 self.assertOutput(original=("var", "x"), output="x")40 def testWithin(self):41 self.assertOutput(42 original=("filter", ("var", "x"), ("var", "y")),43 output="filter(x, y)")44 self.assertOutput(45 original="filter(map(x.y, foo + 5), foo.bar == 5)",46 output="filter(map(x.y, foo + 5), foo.bar == 5)")47 def testMap(self):48 self.assertOutput(49 original=(".", (".", ("var", "x"), "y"), "z"),50 output="x.y.z")51 def testLet(self):52 self.assertOutput(53 original="let(x = 5, y = 10) x * y",54 output="let(x = 5, y = 10) x * y")55 def testNumericExpression(self):56 self.assertOutput(57 original="x + y * 10 + z",58 output="x + y * 10 + z")59 self.assertOutput(60 original="(x + y) * 10 + z",61 output="(x + y) * 10 + z")62 self.assertOutput(63 original="(x + y.w) * (10 + z.w)",64 output="(x + y.w) * (10 + z.w)")65 def testRelation(self):66 self.assertOutput(67 original=("==", ("var", "x"), ("var", "y")),68 output="x == y")69 self.assertOutput(70 original=("!", ("==", ("var", "x"), ("var", "y"))),71 output="x != y")72 self.assertOutput(73 original="x != (y and z)",74 output="x != (y and z)")75 def testLogicalOperation(self):76 self.assertOutput(77 original="(x or y.w) and (10 or z.w)",78 output="(x or y.w) and (10 or z.w)")79 def testComplement(self):80 self.assertOutput(81 original=("!", ("+", 5, 5)),82 output="not (5 + 5)")83 self.assertOutput(84 original=("!", (".", ("var", "x"), "y")),85 output="not x.y")86 def testReverse(self):87 self.assertOutput("reverse((1, 2, 3))", "reverse((1, 2, 3))")88 def testAny(self):89 self.assertOutput(90 ("(SELECT ANY pslist WHERE pid == 1) "91 "AND (SELECT ANY netstat WHERE socket.last_pid == 1)"),92 ("any(pslist, pid == 1) and any(netstat, socket.last_pid == 1)"))93 def testCount(self):94 self.assertOutput("count((1, 2, 3))", "count((1, 2, 3))")95 def testBind(self):96 self.assertOutput("bind('x': 1, 'y': 2)", "bind('x': 1, 'y': 2)")97 def testPair(self):98 self.assertOutput(99 original=(":", "x", ("+", 5, 5)),100 output="'x': (5 + 5)")101 def testCast(self):102 self.assertOutput(103 original=("cast", "5", ("var", "int")),104 output="cast('5', int)")105 def testReducer(self):106 q = query.Query(("reducer", ("var", "count"), ("var", "x")))107 self.assertEqual(asdottysql.asdottysql(q),108 "<Subexpression cannot be formatted as DottySQL.>")109 def testIsInstance(self):110 self.assertOutput(111 original="x isa t",112 output="x isa t")113 self.assertOutput(114 original="(x and y) isa bool",115 output="(x and y) isa bool")116 def testRegexFilter(self):117 self.assertOutput("x =~ '.?'", "x =~ '.?'")118 def testMembership(self):119 self.assertOutput("x in y", "x in y")120 self.assertOutput("x not in y", "x not in y")121 def testApply(self):122 self.assertOutput(123 original=("apply", ("var", "f"), 5, ("+", 5, 5)),124 output="f(5, 5 + 5)")125 self.assertOutput(126 original="func(foo: 10, bar: 15)",127 output="func(foo: 10, bar: 15)")128 def testSelect(self):129 self.assertOutput(130 original="x[5]",131 output="x[5]")132 self.assertOutput(133 original="x[5][5]",134 output="x[5][5]")135 self.assertOutput(136 original="(x or y)[5]",137 output="(x or y)[5]")138 def testResolve(self):139 self.assertOutput(140 original="x.y.z",141 output="x.y.z")142 def testRepeat(self):143 self.assertOutput(144 original="(10, 15, 20 + 5)",145 output="(10, 15, 20 + 5)")146 def testTuple(self):147 self.assertOutput(148 original="[10, 15, 20 + 5]",149 output="[10, 15, 20 + 5]")150 def testIfElse(self):151 self.assertOutput(152 original="if foo then bar else if baz then brr else bzz",153 output="if foo then bar else if baz then brr else bzz")154 self.assertOutput(155 original="if foo then bar",...

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