Skip to content

Commit

Permalink
fix: fix redis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
phantomas1234 committed Mar 3, 2016
1 parent 9da79fb commit 1647b8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions tests/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ def interactive(f):
TRAVIS = os.getenv('TRAVIS', False)
SKIP_PARALLEL = TRAVIS

if os.getenv('WERCKER_REDIS_URL', False):
REDIS_HOST = 'localhost'
else:
REDIS_HOST = os.getenv('WERCKER_REDIS_URL').split('//')[1].split(':')[0]

@interactive
def to_the_power_of_2_interactive(arg):
return arg ** 2
Expand Down Expand Up @@ -94,11 +99,11 @@ def test_length(self):

class TestRedisQueue(unittest.TestCase):
def test_queue_size(self):
queue = RedisQueue("test-queue-size-1", maxsize=1, host=os.getenv('WERCKER_REDIS_HOST', 'localhost'))
queue = RedisQueue("test-queue-size-1", maxsize=1, host=REDIS_HOST)
queue.put(1)
self.assertRaises(six.moves.queue.Full, queue.put, 1)

queue = RedisQueue("test-queue-size-2", maxsize=2, host=os.getenv('WERCKER_REDIS_HOST', 'localhost'))
queue = RedisQueue("test-queue-size-2", maxsize=2, host=REDIS_HOST)
queue.put(1)
queue.put(1)
self.assertRaises(six.moves.queue.Full, queue.put, 1)
Expand All @@ -107,7 +112,7 @@ def test_queue_size(self):
self.assertRaises(six.moves.queue.Empty, queue.get_nowait)

def test_queue_objects(self):
queue = RedisQueue("test-queue", maxsize=100, host=os.getenv('WERCKER_REDIS_HOST', 'localhost'))
queue = RedisQueue("test-queue", maxsize=100, host=REDIS_HOST)
# put int
queue.put(1)
v = queue.get_nowait()
Expand Down Expand Up @@ -140,7 +145,7 @@ def test_queue_objects(self):
self.assertIsInstance(v, dict)

def test_queue_len(self):
queue = RedisQueue("test-queue-len", maxsize=100, host=os.getenv('WERCKER_REDIS_HOST', 'localhost'))
queue = RedisQueue("test-queue-len", maxsize=100, host=REDIS_HOST)
self.assertEqual(queue.length, 0)
queue.put(1)
self.assertEqual(queue.length, 1)
Expand Down
13 changes: 9 additions & 4 deletions tests/test_strain_design_heuristics.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@

TRAVIS = os.getenv('TRAVIS', False)

if os.getenv('WERCKER_REDIS_URL', False):
REDIS_HOST = 'localhost'
else:
REDIS_HOST = os.getenv('WERCKER_REDIS_URL').split('//')[1].split(':')[0]

SEED = 1234

CURRENT_PATH = os.path.dirname(__file__)
Expand Down Expand Up @@ -594,21 +599,21 @@ def setUp(self):

unittest.skipIf(os.getenv('WERCKER', False), 'Currently not working on wercker as redis is not running on localhost')
def test_migrator_constructor(self):
migrator = MultiprocessingMigrator(max_migrants=1)
migrator = MultiprocessingMigrator(max_migrants=1, host=REDIS_HOST)
self.assertIsInstance(migrator.migrants, RedisQueue)
self.assertEqual(migrator.max_migrants, 1)

migrator = MultiprocessingMigrator(max_migrants=2)
migrator = MultiprocessingMigrator(max_migrants=2, host=REDIS_HOST)
self.assertIsInstance(migrator.migrants, RedisQueue)
self.assertEqual(migrator.max_migrants, 2)

migrator = MultiprocessingMigrator(max_migrants=3)
migrator = MultiprocessingMigrator(max_migrants=3, host=REDIS_HOST)
self.assertIsInstance(migrator.migrants, RedisQueue)
self.assertEqual(migrator.max_migrants, 3)

unittest.skipIf(os.getenv('WERCKER', False), 'Currently not working on wercker as redis is not running on localhost')
def test_migrate_individuals_without_evaluation(self):
migrator = MultiprocessingMigrator(max_migrants=1)
migrator = MultiprocessingMigrator(max_migrants=1, host=REDIS_HOST)
self.assertIsInstance(migrator.migrants, RedisQueue)
self.assertEqual(migrator.max_migrants, 1)

Expand Down

0 comments on commit 1647b8a

Please sign in to comment.