Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyrasite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
pyrasite
Commits
617bcd5c
Commit
617bcd5c
authored
Mar 28, 2012
by
Luke Macken
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #28 from ralphbean/feature/context-manager
Make the PyrasiteIPC a context manager as well.
parents
447b4c40
cdca3dfc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
pyrasite/ipc.py
pyrasite/ipc.py
+7
-0
pyrasite/tests/test_ipc.py
pyrasite/tests/test_ipc.py
+31
-0
No files found.
pyrasite/ipc.py
View file @
617bcd5c
...
@@ -69,6 +69,13 @@ class PyrasiteIPC(object):
...
@@ -69,6 +69,13 @@ class PyrasiteIPC(object):
self
.
hostname
=
None
self
.
hostname
=
None
self
.
port
=
None
self
.
port
=
None
def
__enter__
(
self
):
self
.
connect
()
return
self
def
__exit__
(
self
,
*
args
,
**
kwargs
):
self
.
close
()
@
property
@
property
def
title
(
self
):
def
title
(
self
):
if
not
getattr
(
self
,
'_title'
,
None
):
if
not
getattr
(
self
,
'_title'
,
None
):
...
...
pyrasite/tests/test_ipc.py
View file @
617bcd5c
...
@@ -16,12 +16,43 @@
...
@@ -16,12 +16,43 @@
# Copyright (C) 2011, 2012 Red Hat, Inc.
# Copyright (C) 2011, 2012 Red Hat, Inc.
import
os
import
os
import
sys
import
unittest
import
unittest
import
pyrasite
import
pyrasite
from
pyrasite.tests.utils
import
run_program
,
generate_program
,
stop_program
from
pyrasite.tests.utils
import
run_program
,
generate_program
,
stop_program
class
TestIPCContextManager
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
prog
=
generate_program
()
self
.
p
=
run_program
(
self
.
prog
)
def
tearDown
(
self
):
stop_program
(
self
.
p
)
def
test_context_manager
(
self
):
# Check that we're on a version of python that
# supports context managers
info
=
sys
.
version_info
major
,
minor
=
info
[
0
],
info
[
1
]
if
major
<=
2
and
minor
<=
5
:
self
.
skipTest
(
"Context Managers not supported on Python<=2.5"
)
# Check that the context manager injects ipc correctly.
with
pyrasite
.
PyrasiteIPC
(
self
.
p
.
pid
)
as
ipc
:
assert
ipc
.
cmd
(
'print("mu")'
)
==
'mu
\
n
'
# Check that the context manager closes the ipc correctly.
try
:
ipc
.
cmd
(
'print("mu")'
)
assert
False
,
"The connection was not closed."
except
IOError
as
e
:
assert
"Bad file descriptor"
in
str
(
e
)
class
TestIPC
(
unittest
.
TestCase
):
class
TestIPC
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment