# Path: peanut/model.py
# class Post(BaseModel):
#     """Post model
#     """
# 
#     layout = 'post'
# 
#     def __init__(self, title, slug, raw=None, content=None, meta=None):
#         self.title = title
#         self.slug = url_safe(slug)
#         self.content = content
#         self.raw = raw
# 
#         meta = meta or {}
#         self.date = meta.pop('date', None) or datetime.now()
#         self.publish = meta.pop('publish', True)
#         self.layout = meta.pop('layout', Post.layout)
#         self.top = meta.pop('top', False)
#         self.tag_titles = meta.pop('tags', [])
# 
#         image = meta.pop('image', None)
#         if isinstance(image, dict):
#             self.image = image.get('feature', None)
#         else:
#             self.image = image
# 
#         self.meta = meta
# 
#     @property
#     def tags(self):
#         return [Tag(t) for t in self.tag_titles]
# 
#     def __getattr__(self, key):
#         try:
#             return super(Post, self).__getattr__(key)
#         except:
#             pass
#         return self.meta.get(key)
# 
#     def __lt__(self, other):
#         return self.date < other.date
# 
# class Tag(BaseModel):
#     """Tag model
#     """
# 
#     layout = 'tag'
# 
#     def __init__(self, title):
#         self.title = title
#         self.slug = url_safe(title)
# 
#     def __eq__(self, other):
#         return self.title == other.title
# 
#     def __hash__(self):
#         return hash(self.title)
# 
# class Pagination(object):
#     """Pagination"""
# 
#     def __init__(self, posts, page=1, base_url=None, posts_per_page = 5):
#         self._posts = posts
#         # page number starts from 1
#         self.page = page
#         self.base_url = base_url
#         if posts_per_page == 0:
#             posts_per_page = len(self._posts)
#         self.posts_per_page = posts_per_page
# 
#         self.path = None
#         self.url = None
#         self.parse_path_and_url()
# 
#     def parse_path_and_url(self):
#         template = configs.path.pagination
#         relative_path = template.format(
#             number=self.page,
#             num=self.page,
#             n=self.page
#         )
# 
#         if self.page == 1:
#             relative_path = ''
# 
#         file_path = None
#         url = None
#         if re.search(r'index.html?$', self.base_url):
#             # If base_url ends with index.html or index.htm,
#             # insert page path before the index.*
#             parent, index = os.path.split(self.base_url)
#             url = file_path = os.path.join(parent, relative_path, index)
#         else:
#             if not self.base_url.endswith('/'):
#                 self.base_url = self.base_url + '/'
#             else:
#                 if relative_path != '' and not relative_path.endswith('/'):
#                     relative_path = relative_path + '/'
#             url = os.path.join(self.base_url, relative_path)
#             file_path = os.path.join(url, 'index.html')
# 
#         if not url.startswith('/'):
#             url = '/' + url
#         if file_path.startswith('/'):
#             file_path = file_path[1:]
# 
#         self.file_path = url_safe(file_path)
#         self.url = url_safe(url)
# 
#     @property
#     def posts(self):
#         start = (self.page - 1) * self.posts_per_page
#         end = start + self.posts_per_page
#         return self._posts[start:end]
# 
#     @property
#     def total(self):
#         if self.posts_per_page == 0:
#             return 1
#         else:
#             return int((len(self._posts)-1)/self.posts_per_page) + 1
# 
#     @property
#     def next(self):
#         if self.page == self.total:
#             return None
#         return Pagination(self._posts, self.page+1,
#                 self.base_url, self.posts_per_page)
# 
#     @property
#     def prev(self):
#         if self.page == 1:
#             return None
#         return Pagination(self._posts, self.page-1,
#                 self.base_url, self.posts_per_page)
# 
#     def iterate(self):
#         curr = self
#         for i in range(curr.page-1, self.total):
#             yield curr
#             curr = curr.next
# 
# Path: peanut/options.py
# class ValidationError(Exception):
# class LoadingError(ValidationError):
# class Option(dict):
#     def __init__(self, msg=None):
#     def __init__(self, *args, **kwargs):
#     def __setitem__(self, key, value):
#     def __getitem__(self, name):
#     def __delitem__(self, name):
#     def __real_update(self, key, value):
#     def update(self, *args, **kwargs):
# def verify_path():
# def verify_theme():
# def verify_configs():
# def load_yaml(path):
# def load_configs(path):


import unittest
from datetime import datetime
from peanut.model import Post, Tag, Pagination
from peanut.options import configs, env
        self.assertIn(t2, p.tags)

class TestPagination(unittest.TestCase):
    def test_pagination(self):
        posts = []
        for i in range(0, 10):
            title = 'post_{}'.format(i)
            posts.append(Post(title, title, title))

        page = Pagination(posts, base_url='tags/test/', posts_per_page=2)

        self.assertEqual(page.page, 1)
        self.assertEqual(page.total, 5)
        self.assertListEqual(page.posts, posts[0:2])

        self.assertIsNone(page.prev)

        next = page.next
        self.assertListEqual(next.posts, posts[2:4])

        n = 0
        for p in page.iterate():
            self.assertEqual(p.page, n+1)
            self.assertListEqual(p.posts, posts[n*2:n*2+2])
            n += 1

    def test_path(self):
        posts = []
        for i in range(0, 10):
            title = 'post_{}'.format(i)

# Path: peanut/model.py
# class Post(BaseModel):
#     """Post model
#     """
# 
#     layout = 'post'
# 
#     def __init__(self, title, slug, raw=None, content=None, meta=None):
#         self.title = title
#         self.slug = url_safe(slug)
#         self.content = content
#         self.raw = raw
# 
#         meta = meta or {}
#         self.date = meta.pop('date', None) or datetime.now()
#         self.publish = meta.pop('publish', True)
#         self.layout = meta.pop('layout', Post.layout)
#         self.top = meta.pop('top', False)
#         self.tag_titles = meta.pop('tags', [])
# 
#         image = meta.pop('image', None)
#         if isinstance(image, dict):
#             self.image = image.get('feature', None)
#         else:
#             self.image = image
# 
#         self.meta = meta
# 
#     @property
#     def tags(self):
#         return [Tag(t) for t in self.tag_titles]
# 
#     def __getattr__(self, key):
#         try:
#             return super(Post, self).__getattr__(key)
#         except:
#             pass
#         return self.meta.get(key)
# 
#     def __lt__(self, other):
#         return self.date < other.date
# 
# class Tag(BaseModel):
#     """Tag model
#     """
# 
#     layout = 'tag'
# 
#     def __init__(self, title):
#         self.title = title
#         self.slug = url_safe(title)
# 
#     def __eq__(self, other):
#         return self.title == other.title
# 
#     def __hash__(self):
#         return hash(self.title)
# 
# class Pagination(object):
#     """Pagination"""
# 
#     def __init__(self, posts, page=1, base_url=None, posts_per_page = 5):
#         self._posts = posts
#         # page number starts from 1
#         self.page = page
#         self.base_url = base_url
#         if posts_per_page == 0:
#             posts_per_page = len(self._posts)
#         self.posts_per_page = posts_per_page
# 
#         self.path = None
#         self.url = None
#         self.parse_path_and_url()
# 
#     def parse_path_and_url(self):
#         template = configs.path.pagination
#         relative_path = template.format(
#             number=self.page,
#             num=self.page,
#             n=self.page
#         )
# 
#         if self.page == 1:
#             relative_path = ''
# 
#         file_path = None
#         url = None
#         if re.search(r'index.html?$', self.base_url):
#             # If base_url ends with index.html or index.htm,
#             # insert page path before the index.*
#             parent, index = os.path.split(self.base_url)
#             url = file_path = os.path.join(parent, relative_path, index)
#         else:
#             if not self.base_url.endswith('/'):
#                 self.base_url = self.base_url + '/'
#             else:
#                 if relative_path != '' and not relative_path.endswith('/'):
#                     relative_path = relative_path + '/'
#             url = os.path.join(self.base_url, relative_path)
#             file_path = os.path.join(url, 'index.html')
# 
#         if not url.startswith('/'):
#             url = '/' + url
#         if file_path.startswith('/'):
#             file_path = file_path[1:]
# 
#         self.file_path = url_safe(file_path)
#         self.url = url_safe(url)
# 
#     @property
#     def posts(self):
#         start = (self.page - 1) * self.posts_per_page
#         end = start + self.posts_per_page
#         return self._posts[start:end]
# 
#     @property
#     def total(self):
#         if self.posts_per_page == 0:
#             return 1
#         else:
#             return int((len(self._posts)-1)/self.posts_per_page) + 1
# 
#     @property
#     def next(self):
#         if self.page == self.total:
#             return None
#         return Pagination(self._posts, self.page+1,
#                 self.base_url, self.posts_per_page)
# 
#     @property
#     def prev(self):
#         if self.page == 1:
#             return None
#         return Pagination(self._posts, self.page-1,
#                 self.base_url, self.posts_per_page)
# 
#     def iterate(self):
#         curr = self
#         for i in range(curr.page-1, self.total):
#             yield curr
#             curr = curr.next
# 
# Path: peanut/options.py
# class ValidationError(Exception):
# class LoadingError(ValidationError):
# class Option(dict):
#     def __init__(self, msg=None):
#     def __init__(self, *args, **kwargs):
#     def __setitem__(self, key, value):
#     def __getitem__(self, name):
#     def __delitem__(self, name):
#     def __real_update(self, key, value):
#     def update(self, *args, **kwargs):
# def verify_path():
# def verify_theme():
# def verify_configs():
# def load_yaml(path):
# def load_configs(path):


# Path: test/test_model.py
import unittest
from datetime import datetime
from peanut.model import Post, Tag, Pagination
from peanut.options import configs, env

        self.assertIn(t2, p.tags)

class TestPagination(unittest.TestCase):
    def test_pagination(self):
        posts = []
        for i in range(0, 10):
            title = 'post_{}'.format(i)
            posts.append(Post(title, title, title))

        page = Pagination(posts, base_url='tags/test/', posts_per_page=2)

        self.assertEqual(page.page, 1)
        self.assertEqual(page.total, 5)
        self.assertListEqual(page.posts, posts[0:2])

        self.assertIsNone(page.prev)

        next = page.next
        self.assertListEqual(next.posts, posts[2:4])

        n = 0
        for p in page.iterate():
            self.assertEqual(p.page, n+1)
            self.assertListEqual(p.posts, posts[n*2:n*2+2])
            n += 1

    def test_path(self):
        posts = []
        for i in range(0, 10):
            title = 'post_{}'.format(i)

            posts.append(Post(title, title, title))