예제 #1
0
 def test_mismatch_passes_through_to_callable_builtin(self):
     self.patch(matchers, "callable").return_value = False
     result = IsCallable().match(sentinel.function)
     matchers.callable.assert_called_once_with(sentinel.function)
     self.assertIsInstance(result, Mismatch)
     self.assertEqual("%r is not callable" % sentinel.function,
                      result.describe())
예제 #2
0
 def test_mismatch_passes_through_to_callable_builtin(self):
     self.patch(matchers, "callable").return_value = False
     result = IsCallable().match(sentinel.function)
     matchers.callable.assert_called_once_with(sentinel.function)
     self.assertIsInstance(result, Mismatch)
     self.assertEqual(
         "%r is not callable" % sentinel.function,
         result.describe())
예제 #3
0
class MockTestMixin:

    # Some matchers return a private MismatchDecorator object, which
    # does not descend from Mismatch, so we check the contract instead.
    is_mismatch = MatchesStructure(describe=IsCallable(),
                                   get_details=IsCallable())

    def assertMismatch(self, result, message):
        self.assertThat(result, self.is_mismatch)
        self.assertIn(message, result.describe())
예제 #4
0
파일: test_doc.py 프로젝트: karp773/maas
 def test__returns_hash_object(self):
     hasher = hash_canonical(factory.make_string())
     self.assertThat(hasher, MatchesStructure(
         block_size=Equals(64),
         digest=IsCallable(),
         digest_size=Equals(20),
         hexdigest=IsCallable(),
         name=Equals("sha1"),
         update=IsCallable(),
     ))
예제 #5
0
 def test__configure_parses_selected_bucket(self):
     select = SelectBucket()
     parser = OptionParser()
     select.add_options(parser=parser, env={})
     options, rest = parser.parse_args(
         ["--with-select-bucket", "--select-bucket", "8/13"])
     select.configure(options, sentinel.conf)
     self.assertThat(select, MatchesStructure(_selectTest=IsCallable()))
예제 #6
0
 def test_merges_into_new_tree(self):
     xml = self.do_merge_details({
         "lshw": b"<list><foo>Hello</foo></list>",
         "lldp": b"<node><foo>Hello</foo></node>",
     })
     # The presence of a getroot() method indicates that this is a
     # tree object, not an element.
     self.assertThat(xml, MatchesStructure(getroot=IsCallable()))
     # The list tag can be obtained using an XPath expression
     # starting from the root of the tree.
     self.assertSequenceEqual(["list"],
                              [elem.tag for elem in xml.xpath("/list")])
예제 #7
0
 def test_match_passes_through_to_callable_builtin(self):
     self.patch(matchers, "callable").return_value = True
     result = IsCallable().match(sentinel.function)
     matchers.callable.assert_called_once_with(sentinel.function)
     self.assertIs(None, result)
예제 #8
0
 def test_returns_mismatch_when_matchee_is_callable(self):
     result = IsCallable().match(1234)
     self.assertIsInstance(result, Mismatch)
     self.assertEqual("1234 is not callable", result.describe())
예제 #9
0
 def test_returns_none_when_matchee_is_callable(self):
     result = IsCallable().match(lambda: None)
     self.assertIs(None, result)
예제 #10
0
 def test_returns_mismatch_when_matchee_is_callable(self):
     result = IsCallable().match(1234)
     self.assertIsInstance(result, Mismatch)
     self.assertEqual(
         "1234 is not callable",
         result.describe())
예제 #11
0
 def test_connect_to_field_change_returns_two_functions(self):
     callback = Mock()
     connect, disconnect = self.connect(callback, ["name1"])
     self.assertThat(connect, IsCallable())
     self.assertThat(disconnect, IsCallable())