Commit 96c37b18 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Made Projects and Groups be context managers

This will allow for nicer cleanups, especially for those
created in tests.

We're adopting the strong cleanup capability and the larger timeout
in `Project.__exit__()` to mimic what the Project fixtures do, in
the hope to have them simply use the new Context Managers.
parent b528c6d6479e
...@@ -110,3 +110,10 @@ class Group: ...@@ -110,3 +110,10 @@ class Group:
fs_path = self.fs_path() fs_path = self.fs_path()
self.heptapod.run_shell(('mkdir', '-p', fs_path), user='git') self.heptapod.run_shell(('mkdir', '-p', fs_path), user='git')
self.heptapod.put_file_lines(fs_path + '/hgrc', lines) self.heptapod.put_file_lines(fs_path + '/hgrc', lines)
def __enter__(self):
return self
def __exit__(self, *exc_args):
self.api_delete()
return False
...@@ -1138,3 +1138,13 @@ class Project(object): ...@@ -1138,3 +1138,13 @@ class Project(object):
# path on disk actually changes for legacy projects # path on disk actually changes for legacy projects
self._disk_path = None self._disk_path = None
return resp return resp
def __enter__(self):
return self
def __exit__(self, *exc_args):
# let's give a bit more time than usual: this is used for
# cleanups and the instance could be recovering from various errors
self.api_destroy(allow_missing=True, timeout=30)
self.cleanup_teardown()
return False
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment