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

Unified Diff: common/py_utils/py_utils/contextlib_ext_unittest.py

Issue 2585763004: [py_utils] Add empty and optional context managers. (Closed)
Patch Set: rnephew comment Created 4 years 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 | « common/py_utils/py_utils/contextlib_ext.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: common/py_utils/py_utils/contextlib_ext_unittest.py
diff --git a/common/py_utils/py_utils/contextlib_ext_unittest.py b/common/py_utils/py_utils/contextlib_ext_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..b83e7e5e0183c5248c61c745bf2e22d66016fdb3
--- /dev/null
+++ b/common/py_utils/py_utils/contextlib_ext_unittest.py
@@ -0,0 +1,34 @@
+# 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.
+
+import unittest
+
+from py_utils import contextlib_ext
+
+
+class OptionalUnittest(unittest.TestCase):
+
+ class SampleContextMgr(object):
+
+ def __init__(self):
+ self.entered = False
+ self.exited = False
+
+ def __enter__(self):
+ self.entered = True
+
+ def __exit__(self, exc_type, exc_val, exc_tb):
+ self.exited = True
+
+ def testConditionTrue(self):
+ c = self.SampleContextMgr()
+ with contextlib_ext.Optional(c, True):
+ self.assertTrue(c.entered)
+ self.assertTrue(c.exited)
+
+ def testConditionFalse(self):
+ c = self.SampleContextMgr()
+ with contextlib_ext.Optional(c, False):
+ self.assertFalse(c.entered)
+ self.assertFalse(c.exited)
« no previous file with comments | « common/py_utils/py_utils/contextlib_ext.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698