#! /usr/bin/env python2
# -*- coding:utf-8 -*-

import os
import unittest

from sigal.gallery import Gallery
from sigal.settings import read_settings

CURRENT_DIR = os.path.dirname(__file__)


class TestGallery(unittest.TestCase):
    "Test the Gallery class."

    def setUp(self):
        """Read the sample config file."""

        default_conf = os.path.join(CURRENT_DIR, 'sample', 'sigal.conf')
        settings = read_settings(default_conf)
        self.gal = Gallery(settings, os.path.join(CURRENT_DIR, 'sample'),
                           os.path.join(CURRENT_DIR, 'output'))

    def test_filelist(self):
        self.gal.build_paths()
        paths = self.gal.paths

        self.assertItemsEqual(paths.keys(), ['.', 'dir1', 'dir2'])

        self.assertListEqual(paths['.']['img'], [])
        self.assertItemsEqual(paths['.']['subdir'], ['dir1', 'dir2'])

        self.assertItemsEqual(paths['dir1']['img'], ['test1.jpg', 'test2.jpg'])
        self.assertEqual(paths['dir1']['representative'], u'test1.jpg')
        self.assertEqual(paths['dir1']['title'], u'An example gallery')

@@ -101,16 +101,30 @@
  Gallery
+, get_metadata
 %0Afrom si
@@ -269,16 +269,33 @@
 lass.%22%0A%0A
+    @classmethod%0A
     def 
@@ -300,20 +300,19 @@
 f setUp(
-self
+cls
 ):%0A     
@@ -474,28 +474,27 @@
 nf)%0A        
-self
+cls
 .gal = Galle
@@ -569,17 +569,16 @@
         
- 
 os.path.
@@ -605,16 +605,46 @@
 utput'))
+%0A        cls.gal.build_paths()
 %0A%0A    de
@@ -670,39 +670,8 @@
 f):%0A
-        self.gal.build_paths()%0A
     
@@ -754,32 +754,45 @@
 , 'dir1', 'dir2'
+, 'dir1/test'
 %5D)%0A%0A        self
@@ -1126,8 +1126,650 @@
 llery')%0A
+%0A    def test_find_representative(self):%0A        self.assertEqual(self.gal.find_representative('dir1'), u'test1.jpg')%0A        self.assertEqual(self.gal.find_representative('dir1/test'),%0A                         u'test2.jpg')%0A%0A%0Aclass TestMetadata(unittest.TestCase):%0A    %22Test the Gallery class.%22%0A%0A    def test_get_metadata(self):%0A        m = get_metadata(os.path.join(CURRENT_DIR, 'sample', 'dir1'))%0A        self.assertEqual(m%5B'title'%5D, 'An example gallery')%0A        self.assertEqual(m%5B'representative'%5D, 'test1.jpg')%0A%0A        m = get_metadata(os.path.join(CURRENT_DIR, 'sample', 'dir1', 'test'))%0A        self.assertEqual(m%5B'title'%5D, 'Test')%0A

improve tests for gallery