Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't call context managers directly, use the with statement #1433

Merged
merged 1 commit into from
Dec 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions test/worker_multiprocess_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ def run(self):

class MultiprocessWorkerTest(unittest.TestCase):

def setUp(self):
def run(self, result=None):
self.scheduler = RemoteScheduler()
self.scheduler.add_worker = Mock()
self.scheduler.add_task = Mock()
self.worker = Worker(scheduler=self.scheduler, worker_id='X', worker_processes=2).__enter__()

def tearDown(self):
self.worker.__exit__(None, None, None)
with Worker(scheduler=self.scheduler, worker_id='X', worker_processes=2) as worker:
self.worker = worker
super(MultiprocessWorkerTest, self).run(result)

def gw_res(self, pending, task_id):
return dict(n_pending_tasks=pending,
Expand Down
30 changes: 13 additions & 17 deletions test/worker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,16 @@ def run(self):

class WorkerTest(unittest.TestCase):

def setUp(self):
# InstanceCache.disable()
def run(self, result=None):
self.sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
self.w = Worker(scheduler=self.sch, worker_id='X').__enter__()
self.w2 = Worker(scheduler=self.sch, worker_id='Y').__enter__()
self.time = time.time
with Worker(scheduler=self.sch, worker_id='X') as w, Worker(scheduler=self.sch, worker_id='Y') as w2:
self.w = w
self.w2 = w2
super(WorkerTest, self).run(result)

def tearDown(self):
if time.time != self.time:
time.time = self.time
self.w.__exit__(None, None, None)
self.w2.__exit__(None, None, None)

def setTime(self, t):
time.time = lambda: t
Expand Down Expand Up @@ -712,13 +710,12 @@ def custom_email_patch(config):

class WorkerEmailTest(unittest.TestCase):

def setUp(self):
def run(self, result=None):
super(WorkerEmailTest, self).setUp()
sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
self.worker = Worker(scheduler=sch, worker_id="foo").__enter__()

def tearDown(self):
self.worker.__exit__(None, None, None)
with Worker(scheduler=sch, worker_id="foo") as worker:
self.worker = worker
super(WorkerEmailTest, self).run(result)

@email_patch
def test_connection_error(self, emails):
Expand Down Expand Up @@ -967,13 +964,12 @@ def run(self):


class AssistantTest(unittest.TestCase):
def setUp(self):
def run(self, result=None):
self.sch = CentralPlannerScheduler(retry_delay=100, remove_delay=1000, worker_disconnect_delay=10)
self.w = Worker(scheduler=self.sch, worker_id='X').__enter__()
self.assistant = Worker(scheduler=self.sch, worker_id='Y', assistant=True)

def tearDown(self):
self.w.__exit__(None, None, None)
with Worker(scheduler=self.sch, worker_id='X') as w:
self.w = w
super(AssistantTest, self).run(result)

def test_get_work(self):
d = Dummy2Task('123')
Expand Down