Browse Source

improve testing

Oz N Tiram 9 years ago
parent
commit
95012d70c5
2 changed files with 11 additions and 4 deletions
  1. 5 4
      blogit/blogit.py
  2. 6 0
      tests/test_all.py

+ 5 - 4
blogit/blogit.py

@@ -131,9 +131,10 @@ class Tag(object):
         Posts = Query()
         for id in self.posts:
             post = self.db.posts.get(eid=id)
-            if not post:
-                 raise ValueError("no post found for eid %s" % id)
-            yield Entry(os.path.join(CONFIG['content_root'], post['filename']), id)
+            if post:  # pragma: no coverage
+                yield Entry(os.path.join(CONFIG['content_root'], post['filename']), id)
+            else:
+                raise ValueError("No post found for eid %s" % id)
 
     def render(self):
         """Render html page and atom feed"""
@@ -208,7 +209,7 @@ class Entry(object):
         self.id = eid  # this is set inside prepare()
         try:
             self.prepare()
-        except KeyError as E:
+        except KeyError as E:  # pragma: no coverage
             import pdb; pdb.set_trace()
 
     def __str__(self):

+ 6 - 0
tests/test_all.py

@@ -148,6 +148,11 @@ def test_tags():
     with pytest.raises(ValueError):
         new_tag.posts = 1  # This should not either
 
+    new_tag.posts = [100]
+    with pytest.raises(ValueError):
+        list(new_tag.entries)
+
+
 
 def test_slug():
 
@@ -263,6 +268,7 @@ def test_render_index():
 
 
 def test_build():
+    DB._db.purge_tables()
     build(CONFIG)
     # check that the index really contains the last 10 entries
     with open(os.path.join(CONFIG['output_to'], 'index.html')) as html_index: