Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
Kea
Commits
cf59b08a
Commit
cf59b08a
authored
Aug 09, 2012
by
Jelte Jansen
Browse files
[2172] save and restore syscalls in setup/teardown
parent
e107153e
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/lib/python/isc/sysinfo/tests/sysinfo_test.py
View file @
cf59b08a
...
...
@@ -226,6 +226,22 @@ def _my_osx_subprocess_check_output(command):
assert
False
,
'Unhandled command'
class
SysInfoTest
(
unittest
.
TestCase
):
def
setUp
(
self
):
# Save existing implementations of library functions
# (they are replaced in the tests)
self
.
old_platform_system
=
platform
.
system
self
.
old_os_sysconf
=
os
.
sysconf
self
.
old_open
=
__builtins__
.
open
self
.
old_subprocess_check_output
=
subprocess
.
check_output
def
tearDown
(
self
):
# Restore the library functions
platform
.
system
=
self
.
old_platform_system
os
.
sysconf
=
self
.
old_os_sysconf
__builtins__
.
open
=
self
.
old_open
subprocess
.
check_output
=
self
.
old_subprocess_check_output
def
test_sysinfo
(
self
):
"""Test that the various methods on SysInfo exist and return data."""
...
...
@@ -287,15 +303,11 @@ class SysInfoTest(unittest.TestCase):
tests deep into the implementation, and not just the
interfaces."""
#
Save and r
eplace existing implementations of library functions
#
R
eplace existing implementations of library functions
# with mock ones for testing.
old_platform_system
=
platform
.
system
platform
.
system
=
_my_linux_platform_system
old_os_sysconf
=
os
.
sysconf
os
.
sysconf
=
_my_linux_os_sysconf
old_open
=
__builtins__
.
open
__builtins__
.
open
=
_my_linux_open
old_subprocess_check_output
=
subprocess
.
check_output
subprocess
.
check_output
=
_my_linux_subprocess_check_output
s
=
SysInfoFromFactory
()
...
...
@@ -320,26 +332,16 @@ class SysInfoTest(unittest.TestCase):
self
.
assertEqual
(
'osuxbrcc1g9VgaF4yf3FrtfodrfATrbSnjhqhuQSAs8=
\n
'
,
s
.
get_net_stats
())
self
.
assertEqual
(
'Z+w0lwa02/T+5+EIio84rrst/Dtizoz/aL9Im7J7ESA=
\n
'
,
s
.
get_net_connections
())
# Restore original implementations.
platform
.
system
=
old_platform_system
os
.
sysconf
=
old_os_sysconf
__builtins__
.
open
=
old_open
subprocess
.
check_output
=
old_subprocess_check_output
def
test_sysinfo_openbsd
(
self
):
"""Tests the OpenBSD implementation of SysInfo. Note that this
tests deep into the implementation, and not just the
interfaces."""
#
Save and r
eplace existing implementations of library functions
#
R
eplace existing implementations of library functions
# with mock ones for testing.
old_platform_system
=
platform
.
system
platform
.
system
=
_my_openbsd_platform_system
old_os_sysconf
=
os
.
sysconf
os
.
sysconf
=
_my_openbsd_os_sysconf
old_subprocess_check_output
=
subprocess
.
check_output
subprocess
.
check_output
=
_my_openbsd_subprocess_check_output
old_os_uname
=
os
.
uname
os
.
uname
=
_my_openbsd_platform_uname
s
=
SysInfoFromFactory
()
...
...
@@ -370,25 +372,16 @@ class SysInfoTest(unittest.TestCase):
self
.
assertEqual
(
'osuxbrcc1g9VgaF4yf3FrtfodrfATrbSnjhqhuQSAs8=
\n
'
,
s
.
get_net_stats
())
self
.
assertEqual
(
'Z+w0lwa02/T+5+EIio84rrst/Dtizoz/aL9Im7J7ESA=
\n
'
,
s
.
get_net_connections
())
# Restore original implementations.
platform
.
system
=
old_platform_system
os
.
sysconf
=
old_os_sysconf
subprocess
.
check_output
=
old_subprocess_check_output
def
test_sysinfo_freebsd
(
self
):
"""Tests the FreeBSD implementation of SysInfo. Note that this
tests deep into the implementation, and not just the
interfaces."""
#
Save and r
eplace existing implementations of library functions
#
R
eplace existing implementations of library functions
# with mock ones for testing.
old_platform_system
=
platform
.
system
platform
.
system
=
_my_freebsd_platform_system
old_os_sysconf
=
os
.
sysconf
os
.
sysconf
=
_my_freebsd_os_sysconf
old_subprocess_check_output
=
subprocess
.
check_output
subprocess
.
check_output
=
_my_freebsd_subprocess_check_output
old_os_uname
=
os
.
uname
os
.
uname
=
_my_freebsd_platform_uname
s
=
SysInfoFromFactory
()
...
...
@@ -419,25 +412,16 @@ class SysInfoTest(unittest.TestCase):
self
.
assertEqual
(
'osuxbrcc1g9VgaF4yf3FrtfodrfATrbSnjhqhuQSAs8=
\n
'
,
s
.
get_net_stats
())
self
.
assertEqual
(
'Z+w0lwa02/T+5+EIio84rrst/Dtizoz/aL9Im7J7ESA=
\n
'
,
s
.
get_net_connections
())
# Restore original implementations.
platform
.
system
=
old_platform_system
os
.
sysconf
=
old_os_sysconf
subprocess
.
check_output
=
old_subprocess_check_output
def
test_sysinfo_osx
(
self
):
"""Tests the OS X implementation of SysInfo. Note that this
tests deep into the implementation, and not just the
interfaces."""
#
Save and r
eplace existing implementations of library functions
#
R
eplace existing implementations of library functions
# with mock ones for testing.
old_platform_system
=
platform
.
system
platform
.
system
=
_my_osx_platform_system
old_os_sysconf
=
os
.
sysconf
os
.
sysconf
=
_my_osx_os_sysconf
old_subprocess_check_output
=
subprocess
.
check_output
subprocess
.
check_output
=
_my_osx_subprocess_check_output
old_os_uname
=
os
.
uname
os
.
uname
=
_my_osx_platform_uname
s
=
SysInfoFromFactory
()
...
...
@@ -468,10 +452,5 @@ class SysInfoTest(unittest.TestCase):
self
.
assertEqual
(
'osuxbrcc1g9VgaF4yf3FrtfodrfATrbSnjhqhuQSAs8=
\n
'
,
s
.
get_net_stats
())
self
.
assertEqual
(
'Z+w0lwa02/T+5+EIio84rrst/Dtizoz/aL9Im7J7ESA=
\n
'
,
s
.
get_net_connections
())
# Restore original implementations.
platform
.
system
=
old_platform_system
os
.
sysconf
=
old_os_sysconf
subprocess
.
check_output
=
old_subprocess_check_output
if
__name__
==
"__main__"
:
unittest
.
main
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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