예제 #1
0
파일: unit_tests.py 프로젝트: gma/pmock
 def test_matches_both_types_of_arguments(self):
     arg1 = []
     arg2 = []
     args_matcher = self.matcher_class((pmock.same(arg1),),
                                       {"food": pmock.same(arg2)})
     invocation = pmock.Invocation("snake", (arg1,), {"food": arg2})
     self.assert_(args_matcher.matches(invocation))
def test_create_entry():
    """Create a xkcd_feed item from a xkcd_feed and a xkcd_feed entry"""
    agg_feed = AggregateFeed()
    agg_feed.feed_factory = Mock()
    (aggregate_feed, xkcd_feed, entry, converted) = (Mock(), Mock(), Mock(),
                                                     Mock())
    agg_feed.feed_factory.expects(once()).from_parsed_feed(
        same(xkcd_feed), same(entry)).will(return_value(converted))
    aggregate_feed.expects(once()).add(same(converted))
    agg_feed.create_entry(aggregate_feed, xkcd_feed, entry)
    aggregate_feed.verify()
def test_combine_feeds():
    """Should combine feeds into a list of FeedEntries"""
    subject = AggregateFeed()
    mock_feeds = [Mock(), Mock()]
    aggregate_feed = Mock()
    aggregate_feed.expects(once()).add_single_feed(same(aggregate_feed),
                                                   same(mock_feeds[0]))
    aggregate_feed.expects(once()).add_single_feed(same(aggregate_feed),
                                                   same(mock_feeds[1]))
    subject.combine_feeds(aggregate_feed, mock_feeds)
    aggregate_feed.verify()
def test_main():
    """"Main should create a feed and print results"""
    args = ["unused_program_name", "x1"]
    reader = RSReader()
    reader.aggregate_feed = Mock()
    reader.feed_writer = Mock()
    reader.aggregate_feed.expects(once()).from_urls(
        same(reader.aggregate_feed), eq(["x1"]))
    reader.feed_writer.expects(once()).print_entry_listings(same(reader.feed_writer), \
        same(reader.aggregate_feed))
    reader.main(args)
    reader.aggregate_feed.verify()
    reader.feed_writer.verify()
def test_print_entry_listings():
    """Verify that a listing was printed"""
    subject = FeedWriter()
    (feed_writer, aggregate_feed, listings) = (Mock(), Mock(), Mock())
    subject.stdout = Mock()
    aggregate_feed.expects(once()).is_empty().will(return_value(False))
    feed_writer.expects(once()).entry_listings(same(aggregate_feed)).\
        will(return_value(listings))
    subject.stdout.expects(once()).write(same(listings))
    subject.stdout.expects(once()).write(eq(os.linesep))
    subject.print_entry_listings(feed_writer, aggregate_feed)
    feed_writer.verify()
    subject.stdout.verify()
def test_get_feeds_from_urls():
    """Should get a feed for every URL"""
    urls = [Mock(), Mock()]
    feeds = [Mock(), Mock()]
    subject = AggregateFeed()
    subject.feedparser = Mock()
    subject.feedparser.expects(once()).parse(same(urls[0])).will(
        return_value(feeds[0]))
    subject.feedparser.expects(once()).parse(same(urls[1])).will(
        return_value(feeds[1]))
    returned_feeds = subject.feeds_from_urls(urls)
    assert_equals(feeds, returned_feeds)
    subject.feedparser.verify()
예제 #7
0
 def setUp(self):
     self.picolcd_usb = self.mock()
     self.picolcd_handle = self.mock()
     self.picolcd_configuration = self.mock()
     self.picolcd_usb.expects(pmock.once()).open().will(pmock.return_value(self.picolcd_handle))
     self.picolcd_configuration = self.mock()
     self.picolcd_interface = self.mock()
     self.picolcd_configuration.interfaces = [[self.picolcd_interface]]
     self.picolcd_usb.configurations = [self.picolcd_configuration]
     self.picolcd_handle.expects(pmock.once()).detachKernelDriver(pmock.eq(0))
     self.picolcd_handle.expects(pmock.once()).setConfiguration(pmock.same(self.picolcd_configuration))
     self.picolcd_handle.expects(pmock.once()).claimInterface(pmock.same(self.picolcd_interface))
     self.picolcd_handle.expects(pmock.once()).setAltInterface(pmock.same(self.picolcd_interface))
     self.hw = peephole.drivers.picolcd.device.Device(self.picolcd_usb)
예제 #8
0
 def setUp(self):
     self.picolcd_usb = self.mock()
     self.picolcd_handle = self.mock()
     self.picolcd_configuration = self.mock()
     self.picolcd_usb.expects(pmock.once()).open().will(pmock.return_value(self.picolcd_handle))
     self.picolcd_configuration = self.mock()
     self.picolcd_interface = self.mock()
     self.picolcd_configuration.interfaces = [ [ self.picolcd_interface ] ]
     self.picolcd_usb.configurations = [self.picolcd_configuration]
     self.picolcd_handle.expects(pmock.once()).detachKernelDriver(pmock.eq(0))
     self.picolcd_handle.expects(pmock.once()).setConfiguration(pmock.same(self.picolcd_configuration))
     self.picolcd_handle.expects(pmock.once()).claimInterface(pmock.same(self.picolcd_interface))
     self.picolcd_handle.expects(pmock.once()).setAltInterface(pmock.same(self.picolcd_interface))
     self.hw = peephole.drivers.picolcd.device.Device(self.picolcd_usb)
예제 #9
0
 def setUp(self):
     self.mock = pmock.Mock()
     self.toys = ["ball", "stick"]
     self.mock.expects(pmock.once()).method("dog").taking(
         pmock.eq("bone"),
         pmock.same(self.toys),
         pmock.string_contains("slipper"))
예제 #10
0
 def test_notifier_with_message(self):
     self.mock_listener.expects(never()).first_key_heared()
     self.mock_listener.expects(never()).first_key_heared_again()
     self.mock_listener.expects(once()).method('second_key_heared').\
             with_at_least(same('little message'))
     self.notifier.notify('key_with_message', 'little message')
     self.mock_listener.verify()
def test_add_singled_feed():
    """Should add a single xkcd_feed to a set of feeds"""
    entries = [Mock(), Mock()]
    xkcd_feed = {'entries': entries}
    aggregate_feed = Mock()
    aggregate_feed.expects(once()).create_entry(same(aggregate_feed),
                                                same(xkcd_feed),
                                                same(entries[0]))
    aggregate_feed.expects(once()).create_entry(same(aggregate_feed),
                                                same(xkcd_feed),
                                                same(entries[1]))
    AggregateFeed().add_single_feed(aggregate_feed, xkcd_feed)
    aggregate_feed.verify()
def test_from_urls():
    """Should get feeds from URLs and combine them"""
    urls = [Mock(), Mock()]
    feeds = [Mock(), Mock()]
    subject = AggregateFeed()
    aggregate_feed = Mock()
    subject.feedparser = Mock()
    #
    subject.feedparser.expects(once()).parse(same(urls[0])).will(
        return_value(feeds[0]))
    aggregate_feed.expects(once()).\
        add_single_feed(same(aggregate_feed), same(feeds[0]))
    #
    subject.feedparser.expects(once()).parse(same(urls[1])).will(
        return_value(feeds[1]))
    aggregate_feed.expects(once()).\
        add_single_feed(same(aggregate_feed), same(feeds[1]))
    #
    subject.from_urls(aggregate_feed, urls)
    subject.feedparser.verify()
    aggregate_feed.verify()
예제 #13
0
파일: unit_tests.py 프로젝트: gma/pmock
 def test_matches_keyword_arguments(self):
     arg2 = []
     args_matcher = self.matcher_class((), {"food": pmock.same(arg2)})
     invocation = pmock.Invocation("snake", (), {"food": arg2})
     self.assert_(args_matcher.matches(invocation))
예제 #14
0
파일: unit_tests.py 프로젝트: gma/pmock
 def test_matches_arguments(self):
     arg1 = []
     args_matcher = self.matcher_class((pmock.same(arg1),), {})
     self.assert_(
         args_matcher.matches(pmock.Invocation("snake", (arg1,), {})))