Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Unified Diff: chrome/test/kasko/py/kasko/util.py

Issue 1582613002: [win] Create a SyzyAsan/Chrome/Kasko/Crashpad integration test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update file permissions. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/kasko/py/kasko/report.py ('k') | chrome/test/kasko/syzyasan_integration_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/kasko/py/kasko/util.py
diff --git a/chrome/test/kasko/py/kasko/util.py b/chrome/test/kasko/py/kasko/util.py
new file mode 100755
index 0000000000000000000000000000000000000000..4189157fae87dce628080c665c0cda08a309cb4e
--- /dev/null
+++ b/chrome/test/kasko/py/kasko/util.py
@@ -0,0 +1,77 @@
+#!/usr/bin/env python
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Various utilities useful for performing Kasko integration tests."""
+
+import logging
+import os
+import shutil
+import tempfile
+
+
+_LOGGER = logging.getLogger(os.path.basename(__file__))
+
+
+class ScopedTempDir(object):
+ """A class that creates a scoped temporary directory."""
+
+ def __init__(self):
+ self.path_ = None
+
+ def __enter__(self):
+ """Creates the temporary directory and initializes |path|."""
+ self.path_ = tempfile.mkdtemp(prefix='kasko_integration_')
+ return self
+
+ def __exit__(self, *args, **kwargs):
+ """Destroys the temporary directory."""
+ if self.path_ is None:
+ return
+ shutil.rmtree(self.path_)
+
+ @property
+ def path(self):
+ return self.path_
+
+ def release(self):
+ path = self.path_
+ self.path_ = None
+ return path
+
+
+class ScopedStartStop(object):
+ """Utility class for calling 'start' and 'stop' within a scope."""
+
+ def __init__(self, service, start=None, stop=None):
+ self.service_ = service
+
+ if start is None:
+ self.start_ = lambda x: x.start()
+ else:
+ self.start_ = start
+
+ if stop is None:
+ self.stop_ = lambda x: x.stop()
+ else:
+ self.stop_ = stop
+
+ def __enter__(self):
+ self.start_(self.service_)
+ return self
+
+ def __exit__(self, *args, **kwargs):
+ if self.service_:
+ self.stop_(self.service_)
+
+ @property
+ def service(self):
+ """Returns the encapsulated service, retaining ownership."""
+ return self.service_
+
+ def release(self):
+ """Relinquishes ownership of the encapsulated service and returns it."""
+ service = self.service_
+ self.service_ = None
+ return service
« no previous file with comments | « chrome/test/kasko/py/kasko/report.py ('k') | chrome/test/kasko/syzyasan_integration_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698