-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows for automatic cleanup of resources using the with statement. For example: with slapdtest.SlapdObject() as server: server.ldapadd(...) ... When using SlapdObject in a function, it is more convenient and concise than using try/finally pattern.
- Loading branch information
Jon Dufresne
committed
Apr 1, 2018
1 parent
adc40d0
commit 55c96b9
Showing
2 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import unittest | ||
|
||
import slapdtest | ||
|
||
|
||
class TestSlapdObject(unittest.TestCase): | ||
def test_context_manager(self): | ||
with slapdtest.SlapdObject() as server: | ||
self.assertIsNotNone(server._proc) | ||
self.assertIsNone(server._proc) | ||
|
||
def test_context_manager_after_start(self): | ||
server = slapdtest.SlapdObject() | ||
server.start() | ||
self.assertIsNotNone(server._proc) | ||
with server: | ||
self.assertIsNotNone(server._proc) | ||
self.assertIsNone(server._proc) |