Skip to content

Commit

Permalink
Use assertIn/assertNotIn where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Apr 28, 2020
1 parent d5a462d commit 80739b3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion test/backend/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_init(self):
self.assertEqual(conf.oldjobs['expire'].days, 90)
self.assertEqual(conf.admin_email, 'test@salilab.org')
self.assertEqual(conf.limits['running'], 5)
self.assertFalse('concurrent_tasks' in conf.limits)
self.assertNotIn('concurrent_tasks', conf.limits)
self.assertFalse(conf.track_hostname)
self.assertEqual(len(conf.frontends.keys()), 2)
self.assertEqual(conf.frontends['foo']['service_name'], 'Foo')
Expand Down
2 changes: 1 addition & 1 deletion test/backend/test_delete_all_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_web_service(self, config):
web = DummyWeb(None)
mod = DummyModule(web)
out = run_main(mod, 'YES')
self.assertTrue('Are you SURE' in out)
self.assertIn('Are you SURE', out)
self.assertEqual(web.delete_all_jobs_called, True)

web = DummyWeb(None)
Expand Down
4 changes: 2 additions & 2 deletions test/backend/test_local_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ def test_run_wait(self):
break
time.sleep(0.05)
self.assertEqual(LocalRunner._check_completed(pid, ''), False)
self.assertEqual(pid in LocalRunner._waited_jobs, True)
self.assertIn(pid, LocalRunner._waited_jobs)
os.kill(int(pid), signal.SIGTERM)
# Give the waiter thread enough time to close down
for i in range(20):
if pid not in LocalRunner._waited_jobs:
break
time.sleep(0.05)
self.assertEqual(pid in LocalRunner._waited_jobs, False)
self.assertNotIn(pid, LocalRunner._waited_jobs)
# Make sure that non-zero return code causes a job failure
event = ws._event_queue.get(timeout=0)
event.process()
Expand Down
7 changes: 4 additions & 3 deletions test/backend/test_locked_job_dict.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import saliweb.backend
import testutil

class LockedJobDictTest(unittest.TestCase):
"""Check the _LockedJobDict class"""
Expand All @@ -8,11 +9,11 @@ def test_locked_job_dict(self):
"""Check the _LockedJobDict class"""
d = saliweb.backend._LockedJobDict()
self.assertRaises(KeyError, d.remove, 'bar')
self.assertEqual('foo' in d, False)
self.assertNotIn('foo', d)
d.add('foo')
self.assertEqual('foo' in d, True)
self.assertIn('foo', d)
d.remove('foo')
self.assertEqual('foo' in d, False)
self.assertNotIn('foo', d)
self.assertRaises(KeyError, d.remove, 'foo')

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion test/backend/test_make_web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_run(self):
universal_newlines=True)
out, err = p.communicate()
self.assertNotEqual(p.wait(), 0)
self.assertTrue('for a new web service' in err, msg=err)
self.assertIn('for a new web service', err)

def test_get_install_dir_fail(self):
"""Check failure of MakeWebService.get_install_dir() """
Expand Down
2 changes: 1 addition & 1 deletion test/backend/test_sge.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def exit(self):
os.environ['SGE_FOO'] = 'bar'
d = _DRMAAWrapper({'SGE_BAR': 'foo'})
self.assertEqual(os.environ['SGE_BAR'], 'foo')
self.assertFalse('SGE_FOO' in os.environ)
self.assertNotIn('SGE_FOO', os.environ)
del sys.modules['drmaa']

if __name__ == '__main__':
Expand Down
33 changes: 15 additions & 18 deletions test/backend/test_web_service_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,73 +206,70 @@ def test_run(self):
"""Check running web_service.py from the command line"""
out, err, exit = self.run_web_service_subprocess([])
self.assertEqual(exit, 0)
self.assertTrue("Use 'web_service.py help' for help" in out, msg=out)
self.assertIn("Use 'web_service.py help' for help", out)

def test_help(self):
"""Check running web_service.py help"""
for args in [['help'], ['help', 'help']]:
out, err, exit = self.run_web_service(args)
self.assertEqual(exit, 0)
self.assertTrue("for detailed help on any command" in out, msg=out)
self.assertIn("for detailed help on any command", out)

out, err, exit = self.run_web_service(['help', 'info'])
self.assertEqual(exit, 0)
self.assertTrue("Get basic information about a web service" in out,
msg=out)
self.assertIn("Get basic information about a web service", out)

out, err, exit = self.run_web_service(['help', 'badcmd'])
self.assertEqual(exit, 1)
self.assertTrue("Unknown command: 'badcmd'" in out, msg=out)
self.assertIn("Unknown command: 'badcmd'", out)

def test_unknown_command(self):
"""Check running unknown web_service.py command"""
out, err, exit = self.run_web_service(['badcmd'])
self.assertEqual(exit, 1)
self.assertTrue("Unknown command: 'badcmd'" in out, msg=out)
self.assertIn("Unknown command: 'badcmd'", out)

def test_info_command(self):
"""Check running web_service.py info command"""
out, err, exit = self.run_web_service(['info'])
self.assertEqual(exit, 1)
self.assertTrue("sample usage for submitting jobs" in out, msg=out)
self.assertIn("sample usage for submitting jobs", out)
out, err, exit = self.run_web_service(['info', 'http://noparam/'])
self.assertEqual(exit, 0)
self.assertTrue("web_service.py submit http://noparam/ "
"[name1=ARG] [name2=@FILENAME] ..." in out, msg=out)
self.assertIn("web_service.py submit http://noparam/ "
"[name1=ARG] [name2=@FILENAME] ...", out)
out, err, exit = self.run_web_service(['info', 'http://ok/'])
self.assertEqual(exit, 0)
self.assertTrue("web_service.py submit http://ok/ foo=ARG" in out,
msg=out)
self.assertIn("web_service.py submit http://ok/ foo=ARG", out)

def test_submit_command(self):
"""Check running web_service.py submit command"""
out, err, exit = self.run_web_service(['submit'])
self.assertEqual(exit, 1)
self.assertTrue("This only submits the job" in out, msg=out)
self.assertIn("This only submits the job", out)
out, err, exit = self.run_web_service(['submit', 'http://oksubmit/'])
self.assertEqual(exit, 0)
self.assertTrue("Job submitted: results will be found at" in out,
msg=out)
self.assertIn("Job submitted: results will be found at", out)

def test_results_command(self):
"""Check running web_service.py results command"""
out, err, exit = self.run_web_service(['results'])
self.assertEqual(exit, 1)
self.assertTrue("If the job has finished," in out, msg=out)
self.assertIn("If the job has finished,", out)

out, err, exit = self.run_web_service(['results', 'http://jobresults/'])
self.assertEqual(exit, 0)
self.assertTrue("http://results1/" in out, msg=out)
self.assertIn("http://results1/", out)

def test_run_command(self):
"""Check running web_service.py run command"""
out, err, exit = self.run_web_service(['run'])
self.assertEqual(exit, 1)
self.assertTrue("basically the equivalent" in out, msg=out)
self.assertIn("basically the equivalent", out)

out, err, exit = self.run_web_service(['run', 'http://oksubmit/'])
self.assertEqual(exit, 0)
self.assertTrue("http://results1/" in out, msg=out)
self.assertIn("http://results1/", out)

if __name__ == '__main__':
unittest.main()
7 changes: 4 additions & 3 deletions test/build/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import saliweb.build
import tempfile
import shutil
import testutil

class DummyEnv(object):
def __init__(self, exit_val):
Expand Down Expand Up @@ -138,7 +139,7 @@ class DummyConfig:
e.env['config'] = DummyConfig()
t = saliweb.build.builder_perl_tests('dummytgt',
['foo.pl', 'bar.pl'], e)
self.assertTrue('PERL5LIB' in e.env['ENV'])
self.assertIn('PERL5LIB', e.env['ENV'])
self.assertEqual(e.exec_str, "prove foo.pl bar.pl")
self.assertEqual(t, 1)

Expand All @@ -153,8 +154,8 @@ def dummy_func(outdir): pass
['foo.pl', 'bar.pl'], e)
finally:
saliweb.build._fixup_perl_html_coverage = old
self.assertTrue('PERL5LIB' in e.env['ENV'])
self.assertTrue('HARNESS_PERL_SWITCHES' in e.env['ENV'])
self.assertIn('PERL5LIB', e.env['ENV'])
self.assertIn('HARNESS_PERL_SWITCHES', e.env['ENV'])

os.unlink('lib/other.pm')
os.unlink('lib/testser.pm')
Expand Down

0 comments on commit 80739b3

Please sign in to comment.