Skip to content

Commit

Permalink
Merge 6a7b062 into a4a6cf6
Browse files Browse the repository at this point in the history
  • Loading branch information
tribela committed Aug 3, 2013
2 parents a4a6cf6 + 6a7b062 commit 363640e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/libearth.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:maxdepth: 2

libearth/compat
libearth/feed
libearth/repository
libearth/schema
libearth/session
Expand Down
3 changes: 3 additions & 0 deletions docs/libearth/feed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

.. automodule:: libearth.feed
:members:
40 changes: 40 additions & 0 deletions libearth/feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
""":mod:`libearth.feed` --- Feed list
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

from .compat import xrange

class Feed(object):
def __init__(self, path=None):
"""Initializer of Feed list
when path is None, it doesn't save opml file. just use memory
"""
#TODO: save with file, load with file
self.path = path
self.feedlist = {}

def __len__(self):
return len(self.feedlist)

def __repr__(self):
return '<{0.__module__}.{0.__name__} using {1}>'.format(type(self), self.path)

def add_feed(self, title, url):
if url in self.feedlist:
raise AlreadyExistException("{0} is already Exist".format(title))
self.feedlist[url] = {'title': title}

def remove_feed(self, url):
"""Remove feed from feed list
:returns: :const:`True` when successfuly removed. :const:`False` when have not to or failed to remove.
:rtype: :class:`bool`
"""
if url not in self.feedlist:
return False
else:
self.feedlist.pop(url)
return True

class AlreadyExistException(Exception):
pass
23 changes: 23 additions & 0 deletions tests/feed_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pytest import raises

from libearth.compat import xrange
from libearth.feed import Feed, AlreadyExistException

def test_count_empty_list():
f = Feed()
assert len(f) == 0

def test_count_duplicated_url():
f = Feed()
with raises(AlreadyExistException):
for i in xrange(30):
f.add_feed('title', 'url')

assert len(f) == 1

def test_count_after_remove():
f = Feed()
f.add_feed('title', 'url')
f.remove_feed('url')

assert len(f) == 0

0 comments on commit 363640e

Please sign in to comment.