/usr/lib/python3/dist-packages/plainbox/impl/test_validation.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 101 102 103 104 105 106 107 108 109 110 111 112 | # This file is part of Checkbox.
#
# Copyright 2014 Canonical Ltd.
# Written by:
# Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# Checkbox 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 Checkbox. If not, see <http://www.gnu.org/licenses/>.
"""
plainbox.impl.test_validation
=============================
Test definitions for plainbox.impl.validation module
"""
from unittest import TestCase
from plainbox.impl.validation import ValidationError
from plainbox.impl.validation import Issue
from plainbox.vendor import mock
class ValidationErrorTests(TestCase):
def test_smoke__no_hint(self):
err = ValidationError('field', 'problem')
self.assertEqual(str(err), "Problem with field field: problem")
self.assertEqual(repr(err), (
"ValidationError("
"field='field', problem='problem', hint=None, origin=None)"))
def test_smoke__hint(self):
err = ValidationError('field', 'problem', 'hint')
self.assertEqual(str(err), "Problem with field field: problem")
self.assertEqual(repr(err), (
"ValidationError("
"field='field', problem='problem', hint='hint', origin=None)"))
def test_smoke__origin(self):
err = ValidationError('field', 'problem', origin='origin')
self.assertEqual(str(err), "Problem with field field: problem")
self.assertEqual(repr(err), (
"ValidationError("
"field='field', problem='problem', hint=None, origin='origin')"))
class IssueTests(TestCase):
def setUp(self):
self.message = mock.MagicMock(name='message')
self.severity = mock.MagicMock(name='severity')
self.kind = mock.MagicMock(name='kind')
self.origin = mock.MagicMock(name='origin')
self.issue = Issue(self.message, self.severity, self.kind, self.origin)
def test_init(self):
self.assertIs(self.issue.message, self.message)
self.assertIs(self.issue.severity, self.severity)
self.assertIs(self.issue.kind, self.kind)
self.assertIs(self.issue.origin, self.origin)
def test_str__with_origin(self):
self.message.__str__.return_value = '<message>'
self.origin.__str__.return_value = '<origin>'
self.kind.__str__.return_value = '<kind>'
self.severity.__str__.return_value = '<severity>'
self.assertEqual(str(self.issue), "<origin>: <severity>: <message>")
def test_str__without_origin(self):
self.issue.origin = None
self.message.__str__.return_value = '<message>'
self.kind.__str__.return_value = '<kind>'
self.severity.__str__.return_value = '<severity>'
self.assertEqual(str(self.issue), "<severity>: <message>")
def test_repr__with_origin(self):
self.message.__repr__ = lambda mock: '(message)'
self.origin.__repr__ = lambda mock: '(origin)'
self.kind.__repr__ = lambda mock: '(kind)'
self.severity.__repr__ = lambda mock: '(severity)'
self.assertEqual(
repr(self.issue), (
'Issue(message=(message), severity=(severity),'
' kind=(kind), origin=(origin))'))
def test_relative_to__with_origin(self):
path = 'path'
issue2 = self.issue.relative_to(path)
self.issue.origin.relative_to.assert_called_with(path)
self.assertIs(self.issue.message, issue2.message)
self.assertIs(self.issue.severity, issue2.severity)
self.assertIs(self.issue.kind, issue2.kind)
self.assertIs(self.issue.origin.relative_to(path), issue2.origin)
def test_relative_to__without_origin(self):
path = 'path'
self.issue.origin = None
issue2 = self.issue.relative_to(path)
self.assertIs(issue2.message, self.issue.message)
self.assertIs(issue2.severity, self.issue.severity)
self.assertIs(issue2.kind, self.issue.kind)
self.assertIs(issue2.origin, None)
|