Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from zopefoundation/test-coverage
Improve test coverage
- Loading branch information
Showing
9 changed files
with
94 additions
and
48 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 |
---|---|---|
@@ -1 +1,21 @@ | ||
# Make this a package. | ||
import sys | ||
from contextlib import contextmanager | ||
from io import StringIO, BytesIO | ||
|
||
|
||
# By using io.BytesIO() instead of cStringIO.StringIO() on Python 2 we make | ||
# sure we're not trying to accidentally print unicode to stdout/stderr. | ||
NativeStringIO = BytesIO if str is bytes else StringIO | ||
|
||
|
||
@contextmanager | ||
def capture_output(stdout=None, stderr=None): | ||
old_stdout = sys.stdout | ||
old_stderr = sys.stderr | ||
sys.stdout = stdout = stdout or NativeStringIO() | ||
sys.stderr = stderr = stderr or NativeStringIO() | ||
try: | ||
yield stdout, stderr | ||
finally: | ||
sys.stdout = old_stdout | ||
sys.stderr = old_stderr |
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,20 @@ | ||
import unittest | ||
|
||
from zope.app.server.main import main, load_options | ||
from zope.app.server.tests import capture_output | ||
|
||
|
||
class TestMain(unittest.TestCase): | ||
|
||
def test_main(self): | ||
with self.assertRaises(SystemExit) as cm: | ||
with capture_output() as (stdout, stderr): | ||
main(['invalid']) | ||
self.assertEqual(cm.exception.code, 2) | ||
self.assertNotEqual(stderr.getvalue(), "") | ||
|
||
def test_load_options_no_config_file_specified(self): | ||
options = load_options([]) | ||
self.assertIs(options, None) | ||
|
||
# TODO: somebody finish this please |
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,23 @@ | ||
import unittest | ||
|
||
import zope.app.server.main | ||
from zope.interface.verify import verifyObject | ||
from zope.app.server.servercontrol import serverControl | ||
from zope.applicationcontrol.interfaces import IServerControl | ||
|
||
|
||
class TestServerControl(unittest.TestCase): | ||
|
||
def tearDown(self): | ||
zope.app.server.main.exit_status = None | ||
|
||
def test(self): | ||
verifyObject(IServerControl, serverControl) | ||
|
||
def test_shutdown(self): | ||
serverControl.shutdown() | ||
self.assertEqual(zope.app.server.main.exit_status, 0) | ||
|
||
def test_restart(self): | ||
serverControl.restart() | ||
self.assertEqual(zope.app.server.main.exit_status, 1) |
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,7 @@ | ||
import unittest | ||
|
||
|
||
class TestZpasswdDeprecation(unittest.TestCase): | ||
|
||
def test(self): | ||
from zope.app.server.zpasswd import Principal # noqa |
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