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())
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())
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())
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(), ))
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()))
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")])
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)
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())
def test_returns_none_when_matchee_is_callable(self): result = IsCallable().match(lambda: None) self.assertIs(None, result)
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())
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())