From 043f08258c4d7ba3f71b5524b39d7e3b00cc06dc Mon Sep 17 00:00:00 2001 From: Mikel Larreategi Date: Fri, 12 Feb 2016 09:41:47 +0100 Subject: [PATCH] user assertTrue instead of assertIn, py26 doesn't have assertIn --- superlance/tests/httpok_test.py | 77 +++++++++++++++++---------------- superlance/tests/memmon_test.py | 64 +++++++++++++-------------- 2 files changed, 71 insertions(+), 70 deletions(-) diff --git a/superlance/tests/httpok_test.py b/superlance/tests/httpok_test.py index cac33ca..2776a00 100644 --- a/superlance/tests/httpok_test.py +++ b/superlance/tests/httpok_test.py @@ -206,14 +206,14 @@ def test_runforever_eager_error_on_request_some(self): prog.stdin.seek(0) prog.runforever(test=True) lines = prog.stderr.getvalue().split('\n') - self.assertIn("Restarting selected processes ['foo', 'bar', " - "'baz_01', 'notexisting']", lines[0]) - self.assertIn('foo is in RUNNING state, restarting', lines[1]) - self.assertIn('foo restarted', lines[2]) - self.assertIn('bar not in RUNNING state, NOT restarting', lines[3]) - self.assertIn('baz:baz_01 not in RUNNING state, NOT restarting', + self.assertTrue("Restarting selected processes ['foo', 'bar', " + "'baz_01', 'notexisting']" in lines[0]) + self.assertTrue('foo is in RUNNING state, restarting' in lines[1]) + self.assertTrue('foo restarted' in lines[2]) + self.assertTrue('bar not in RUNNING state, NOT restarting' in lines[3]) + self.assertTrue('baz:baz_01 not in RUNNING state, NOT restarting' in lines[4]) - self.assertIn("Programs not restarted because " + self.assertTrue("Programs not restarted because " "they did not exist: ['notexisting']", lines[5]) mailed = prog.mailed.split('\n') self.assertEqual(len(mailed), 12) @@ -229,11 +229,11 @@ def test_runforever_eager_error_on_request_any(self): prog.stdin.seek(0) prog.runforever(test=True) lines = prog.stderr.getvalue().split('\n') - self.assertIn('Restarting all running processes', lines[0]) - self.assertIn('foo is in RUNNING state, restarting', lines[1]) - self.assertIn('foo restarted', lines[2]) - self.assertIn('bar not in RUNNING state, NOT restarting', lines[3]) - self.assertIn('baz:baz_01 not in RUNNING state, NOT restarting', + self.assertTrue('Restarting all running processes' in lines[0]) + self.assertTrue('foo is in RUNNING state, restarting' in lines[1]) + self.assertTrue('foo restarted' in lines[2]) + self.assertTrue('bar not in RUNNING state, NOT restarting' in lines[3]) + self.assertTrue('baz:baz_01 not in RUNNING state, NOT restarting' in lines[4]) mailed = prog.mailed.split('\n') self.assertEqual(len(mailed), 11) @@ -250,11 +250,11 @@ def test_runforever_eager_error_on_process_stop(self): prog.stdin.seek(0) prog.runforever(test=True) lines = prog.stderr.getvalue().split('\n') - self.assertIn("Restarting selected processes ['FAILED']", lines[0]) - self.assertIn('foo:FAILED is in RUNNING state, restarting', lines[1]) - self.assertIn("Failed to stop process foo:FAILED: " - "", lines[2]) - self.assertIn('foo:FAILED restarted', lines[3]) + self.assertTrue("Restarting selected processes ['FAILED']" in lines[0]) + self.assertTrue('foo:FAILED is in RUNNING state, restarting' in lines[1]) + self.assertTrue("Failed to stop process foo:FAILED: " + "" in lines[2]) + self.assertTrue('foo:FAILED restarted' in lines[3]) mailed = prog.mailed.split('\n') self.assertEqual(len(mailed), 10) self.assertEqual(mailed[0], 'To: chrism@plope.com') @@ -270,11 +270,11 @@ def test_runforever_eager_error_on_process_start(self): prog.stdin.seek(0) prog.runforever(test=True) lines = prog.stderr.getvalue().split('\n') - self.assertIn("Restarting selected processes ['SPAWN_ERROR']", lines[0]) - self.assertIn('foo:SPAWN_ERROR is in RUNNING state, restarting', + self.assertTrue("Restarting selected processes ['SPAWN_ERROR']" in lines[0]) + self.assertTrue('foo:SPAWN_ERROR is in RUNNING state, restarting' in lines[1]) - self.assertIn("Failed to start process foo:SPAWN_ERROR: " - "", lines[2]) + self.assertTrue("Failed to start process foo:SPAWN_ERROR: " + "" in lines[2]) mailed = prog.mailed.split('\n') self.assertEqual(len(mailed), 9) self.assertEqual(mailed[0], 'To: chrism@plope.com') @@ -290,18 +290,18 @@ def test_runforever_eager_gcore(self): prog.stdin.seek(0) prog.runforever(test=True) lines = prog.stderr.getvalue().split('\n') - self.assertIn("Restarting selected processes ['foo', 'bar', " - "'baz_01', 'notexisting']", lines[0]) - self.assertIn('gcore output for foo:', lines[1]) + self.assertTrue("Restarting selected processes ['foo', 'bar', " + "'baz_01', 'notexisting']" in lines[0]) + self.assertTrue('gcore output for foo:' in lines[1]) self.assertEqual(lines[2], '') self.assertEqual(lines[3], ' ') - self.assertIn('foo is in RUNNING state, restarting', lines[4]) - self.assertIn('foo restarted', lines[5]) - self.assertIn('bar not in RUNNING state, NOT restarting', lines[6]) - self.assertIn('baz:baz_01 not in RUNNING state, NOT restarting', + self.assertTrue('foo is in RUNNING state, restarting' in lines[4]) + self.assertTrue('foo restarted' in lines[5]) + self.assertTrue('bar not in RUNNING state, NOT restarting' in lines[6]) + self.assertTrue('baz:baz_01 not in RUNNING state, NOT restarting' in lines[7]) - self.assertIn("Programs not restarted because they did not exist: " - "['notexisting']", lines[8]) + self.assertTrue("Programs not restarted because they did not exist: " + "['notexisting']" in lines[8]) mailed = prog.mailed.split('\n') self.assertEqual(len(mailed), 15) self.assertEqual(mailed[0], 'To: chrism@plope.com') @@ -328,10 +328,10 @@ def test_runforever_not_eager_running(self): prog.stdin.seek(0) prog.runforever(test=True) lines = [x for x in prog.stderr.getvalue().split('\n') if x] - self.assertIn("Restarting selected processes ['foo', 'bar']", lines[0]) - self.assertIn('foo is in RUNNING state, restarting', lines[1]) - self.assertIn('foo restarted', lines[2]) - self.assertIn('bar not in RUNNING state, NOT restarting', lines[3]) + self.assertTrue("Restarting selected processes ['foo', 'bar']" in lines[0]) + self.assertTrue('foo is in RUNNING state, restarting' in lines[1]) + self.assertTrue('foo restarted' in lines[2]) + self.assertTrue('bar not in RUNNING state, NOT restarting' in lines[3]) mailed = prog.mailed.split('\n') self.assertEqual(len(mailed), 10) self.assertEqual(mailed[0], 'To: chrism@plope.com') @@ -361,10 +361,11 @@ def test_runforever_connrefused_error(self): prog.stdin.seek(0) prog.runforever(test=True) lines = [x for x in prog.stderr.getvalue().split('\n') if x] - self.assertIn("Restarting selected processes ['foo', 'bar']", lines[0]) - self.assertIn('foo is in RUNNING state, restarting', lines[1]) - self.assertIn('foo restarted', lines[2]) - self.assertIn('bar not in RUNNING state, NOT restarting', lines[3]) + self.assertTrue("Restarting selected processes ['foo', 'bar']" + in lines[0]) + self.assertTrue('foo is in RUNNING state, restarting' in lines[1]) + self.assertTrue('foo restarted' in lines[2]) + self.assertTrue('bar not in RUNNING state, NOT restarting' in lines[3]) mailed = prog.mailed.split('\n') self.assertEqual(len(mailed), 10) self.assertEqual(mailed[0], 'To: chrism@plope.com') diff --git a/superlance/tests/memmon_test.py b/superlance/tests/memmon_test.py index 095ff9b..b936294 100644 --- a/superlance/tests/memmon_test.py +++ b/superlance/tests/memmon_test.py @@ -54,13 +54,13 @@ def test_runforever_tick_programs(self): memmon.runforever(test=True) lines = memmon.stderr.getvalue().split('\n') self.assertEqual(len(lines), 8) - self.assertIn('Checking programs bar=0, baz_01=0, foo=0', lines[0]) - self.assertIn('RSS of foo:foo is 2264064', lines[1]) - self.assertIn('Restarting foo:foo', lines[2]) - self.assertIn('RSS of bar:bar is 2265088', lines[3]) - self.assertIn('Restarting bar:bar', lines[4]) - self.assertIn('RSS of baz:baz_01 is 2265088', lines[5]) - self.assertIn('Restarting baz:baz_01', lines[6]) + self.assertTrue('Checking programs bar=0, baz_01=0, foo=0' in lines[0]) + self.assertTrue('RSS of foo:foo is 2264064' in lines[1]) + self.assertTrue('Restarting foo:foo' in lines[2]) + self.assertTrue('RSS of bar:bar is 2265088' in lines[3]) + self.assertTrue('Restarting bar:bar' in lines[4]) + self.assertTrue('RSS of baz:baz_01 is 2265088' in lines[5]) + self.assertTrue('Restarting baz:baz_01' in lines[6]) self.assertEqual(lines[7], '') mailed = memmon.mailed.split('\n') self.assertEqual(len(mailed), 4) @@ -80,9 +80,9 @@ def test_runforever_tick_groups(self): memmon.runforever(test=True) lines = memmon.stderr.getvalue().split('\n') self.assertEqual(len(lines), 4) - self.assertIn('Checking groups foo=0', lines[0]) - self.assertIn('RSS of foo:foo is 2264064', lines[1]) - self.assertIn('Restarting foo:foo', lines[2]) + self.assertTrue('Checking groups foo=0' in lines[0]) + self.assertTrue('RSS of foo:foo is 2264064' in lines[1]) + self.assertTrue('Restarting foo:foo' in lines[2]) self.assertEqual(lines[3], '') mailed = memmon.mailed.split('\n') self.assertEqual(len(mailed), 4) @@ -102,13 +102,13 @@ def test_runforever_tick_any(self): memmon.runforever(test=True) lines = memmon.stderr.getvalue().split('\n') self.assertEqual(len(lines), 8) - self.assertIn('Checking any=0', lines[0]) - self.assertIn('RSS of foo:foo is 2264064', lines[1]) - self.assertIn('Restarting foo:foo', lines[2]) - self.assertIn('RSS of bar:bar is 2265088', lines[3]) - self.assertIn('Restarting bar:bar', lines[4]) - self.assertIn('RSS of baz:baz_01 is 2265088', lines[5]) - self.assertIn('Restarting baz:baz_01', lines[6]) + self.assertTrue('Checking any=0' in lines[0]) + self.assertTrue('RSS of foo:foo is 2264064' in lines[1]) + self.assertTrue('Restarting foo:foo' in lines[2]) + self.assertTrue('RSS of bar:bar is 2265088' in lines[3]) + self.assertTrue('Restarting bar:bar' in lines[4]) + self.assertTrue('RSS of baz:baz_01 is 2265088' in lines[5]) + self.assertTrue('Restarting baz:baz_01' in lines[6]) self.assertEqual(lines[7], '') mailed = memmon.mailed.split('\n') self.assertEqual(len(mailed), 4) @@ -123,12 +123,12 @@ def test_runforever_tick_programs_and_groups(self): memmon.runforever(test=True) lines = memmon.stderr.getvalue().split('\n') self.assertEqual(len(lines), 7) - self.assertIn('Checking programs baz_01=0', lines[0]) - self.assertIn('Checking groups foo=0', lines[1]) - self.assertIn('RSS of foo:foo is 2264064', lines[2]) - self.assertIn('Restarting foo:foo', lines[3]) - self.assertIn('RSS of baz:baz_01 is 2265088', lines[4]) - self.assertIn('Restarting baz:baz_01', lines[5]) + self.assertTrue('Checking programs baz_01=0' in lines[0]) + self.assertTrue('Checking groups foo=0' in lines[1]) + self.assertTrue('RSS of foo:foo is 2264064' in lines[2]) + self.assertTrue('Restarting foo:foo' in lines[3]) + self.assertTrue('RSS of baz:baz_01 is 2265088' in lines[4]) + self.assertTrue('Restarting baz:baz_01' in lines[5]) self.assertEqual(lines[6], '') mailed = memmon.mailed.split('\n') self.assertEqual(len(mailed), 4) @@ -148,8 +148,8 @@ def test_runforever_tick_programs_norestart(self): memmon.runforever(test=True) lines = memmon.stderr.getvalue().split('\n') self.assertEqual(len(lines), 3) - self.assertIn('Checking programs foo=%s' % maxint, lines[0]) - self.assertIn('RSS of foo:foo is 2264064', lines[1]) + self.assertTrue('Checking programs foo=%s' % maxint in lines[0]) + self.assertTrue('RSS of foo:foo is 2264064' in lines[1]) self.assertEqual(lines[2], '') self.assertEqual(memmon.mailed, False) @@ -163,8 +163,8 @@ def test_stopprocess_fault_tick_programs_norestart(self): memmon.runforever(test=True) lines = memmon.stderr.getvalue().split('\n') self.assertEqual(len(lines), 3) - self.assertIn('Checking programs foo=%s' % maxint, lines[0]) - self.assertIn('RSS of foo:foo is 2264064', lines[1]) + self.assertTrue('Checking programs foo=%s' % maxint in lines[0]) + self.assertTrue('RSS of foo:foo is 2264064' in lines[1]) self.assertEqual(lines[2], '') self.assertEqual(memmon.mailed, False) @@ -192,17 +192,17 @@ def test_stopprocess_fails_to_stop(self): self.assertRaises(xmlrpclib.Fault, memmon.runforever, True) lines = memmon.stderr.getvalue().split('\n') self.assertEqual(len(lines), 4) - self.assertIn('Checking programs BAD_NAME=%s' % 0, lines[0]) - self.assertIn('RSS of BAD_NAME:BAD_NAME is 2264064', lines[1]) - self.assertIn('Restarting BAD_NAME:BAD_NAME', lines[2]) - self.assertIn('Failed', lines[3]) + self.assertTrue('Checking programs BAD_NAME=%s' % 0 in lines[0]) + self.assertTrue('RSS of BAD_NAME:BAD_NAME is 2264064' in lines[1]) + self.assertTrue('Restarting BAD_NAME:BAD_NAME' in lines[2]) + self.assertTrue('Failed' in lines[3]) mailed = memmon.mailed.split('\n') self.assertEqual(len(mailed), 4) self.assertEqual(mailed[0], 'To: chrism@plope.com') self.assertEqual(mailed[1], 'Subject: memmon: failed to stop process BAD_NAME:BAD_NAME, exiting') self.assertEqual(mailed[2], '') - self.assertIn('Failed', mailed[3]) + self.assertTrue('Failed' in mailed[3]) def test_subject_no_name(self): """set the name to None to check if subject formats to: