Andrea Frittoli | b6e1a28 | 2014-08-05 20:08:27 +0100 | [diff] [blame] | 1 | # Copyright 2014 Hewlett-Packard Development Company, L.P. |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
| 16 | from tempest.common import custom_matchers |
Matthew Treinish | ffad78a | 2016-04-16 14:39:52 -0400 | [diff] [blame] | 17 | from tempest.tests import base |
Andrea Frittoli | b6e1a28 | 2014-08-05 20:08:27 +0100 | [diff] [blame] | 18 | |
| 19 | from testtools.tests.matchers import helpers |
| 20 | |
| 21 | |
| 22 | class TestMatchesDictExceptForKeys(base.TestCase, |
| 23 | helpers.TestMatchersInterface): |
| 24 | |
| 25 | matches_matcher = custom_matchers.MatchesDictExceptForKeys( |
| 26 | {'a': 1, 'b': 2, 'c': 3, 'd': 4}, ['c', 'd']) |
| 27 | matches_matches = [ |
| 28 | {'a': 1, 'b': 2, 'c': 3, 'd': 4}, |
| 29 | {'a': 1, 'b': 2, 'c': 5}, |
| 30 | {'a': 1, 'b': 2}, |
| 31 | ] |
| 32 | matches_mismatches = [ |
| 33 | {}, |
| 34 | {'foo': 1}, |
| 35 | {'a': 1, 'b': 3}, |
| 36 | {'a': 1, 'b': 2, 'foo': 1}, |
| 37 | {'a': 1, 'b': None, 'foo': 1}, |
| 38 | ] |
| 39 | |
| 40 | str_examples = [] |
| 41 | describe_examples = [ |
| 42 | ("Only in expected:\n" |
| 43 | " {'a': 1, 'b': 2}\n", |
| 44 | {}, |
| 45 | matches_matcher), |
| 46 | ("Only in expected:\n" |
| 47 | " {'a': 1, 'b': 2}\n" |
| 48 | "Only in actual:\n" |
| 49 | " {'foo': 1}\n", |
| 50 | {'foo': 1}, |
| 51 | matches_matcher), |
| 52 | ("Differences:\n" |
| 53 | " b: expected 2, actual 3\n", |
| 54 | {'a': 1, 'b': 3}, |
| 55 | matches_matcher), |
| 56 | ("Only in actual:\n" |
| 57 | " {'foo': 1}\n", |
| 58 | {'a': 1, 'b': 2, 'foo': 1}, |
| 59 | matches_matcher), |
| 60 | ("Only in actual:\n" |
| 61 | " {'foo': 1}\n" |
| 62 | "Differences:\n" |
| 63 | " b: expected 2, actual None\n", |
| 64 | {'a': 1, 'b': None, 'foo': 1}, |
| 65 | matches_matcher) |
Joe Gordon | 28788b4 | 2015-02-25 12:42:37 -0800 | [diff] [blame] | 66 | ] |