/usr/lib/python3/dist-packages/plainbox/vendor/extcmd/test.py is in python3-plainbox 0.25-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | # Copyright (c) 2010-2012 Linaro Limited
# Copyright (c) 2013 Canonical Ltd.
#
# Author: Zygmunt Krynicki <zygmunt.krynicki@linaro.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import doctest
import unittest
from plainbox.vendor import extcmd
def test_suite():
suite = unittest.defaultTestLoader.loadTestsFromName("extcmd.test")
suite.addTests(doctest.DocTestSuite(extcmd))
return suite
class Dummy:
"""
Dummy class that has deterministic __repr__()
"""
def __repr__(self):
return "<Dummy>"
class ReprTests(unittest.TestCase):
def test_safe_delegate(self):
obj = extcmd.SafeDelegate(Dummy())
self.assertEqual(repr(obj), "<SafeDelegate wrapping <Dummy>>")
def test_chain(self):
obj = extcmd.Chain([Dummy()])
self.assertEqual(
repr(obj), "<Chain [<SafeDelegate wrapping <Dummy>>]>")
def test_redirect(self):
obj = extcmd.Redirect(stdout=Dummy(), stderr=Dummy())
self.assertEqual(
repr(obj), "<Redirect stdout:<Dummy> stderr:<Dummy>>")
def test_transform(self):
obj = extcmd.Transform(callback=Dummy(), delegate=Dummy())
self.assertEqual(
repr(obj), ("<Transform callback:<Dummy> delegate:<SafeDelegate"
" wrapping <Dummy>>>"))
def test_decode(self):
obj = extcmd.Decode(delegate=Dummy())
self.assertEqual(
repr(obj), ("<Decode encoding:'UTF-8'"
" delegate:<SafeDelegate wrapping <Dummy>>>"))
def test_encode(self):
obj = extcmd.Encode(delegate=Dummy())
self.assertEqual(
repr(obj), ("<Encode encoding:'UTF-8'"
" delegate:<SafeDelegate wrapping <Dummy>>>"))
class Detector:
"""
Auxiliary class that records if on_begin() and on_end() got called
"""
on_begin_called = False
on_end_called = False
def on_begin(self, args, kwargs):
self.on_begin_called = True
def on_end(self, returncode):
self.on_end_called = True
class PropagationTests(unittest.TestCase):
def test_transform(self):
detector = Detector()
self.assertEqual(detector.on_begin_called, False)
self.assertEqual(detector.on_end_called, False)
obj = extcmd.Transform(lambda data: data, detector)
obj.on_begin(None, None)
obj.on_end(None)
self.assertEqual(detector.on_begin_called, True)
self.assertEqual(detector.on_end_called, True)
|