# Path: mcomix/last_read_page.py
# class LastReadPage(object):
#     def __init__(self, dbfile):
#     def cleanup(self):
#     def set_enabled(self, enabled):
#     def count(self):
#     def set_page(self, path, page):
#     def clear_page(self, path):
#     def clear_all(self):
#     def get_page(self, path):
#     def get_date(self, path):
#     def _init_database(self, dbfile):


import unittest
import tempfile
import os
from mcomix import last_read_page

    def test_nonexistant_file(self):
        self.assertRaises(ValueError, self.lastread.set_page,
            '/root/mcomix/file-that-should-not-exist-hopefully', 1)

    def test_invalid_page(self):
        self.assertRaises(ValueError, self.lastread.set_page,
            self.archive1, 0)
        self.assertRaises(ValueError, self.lastread.set_page,
            self.archive1, -1)

    def test_date(self):
        self.lastread.set_page(self.archive1, 1)
        self.assertIsNotNone(self.lastread.get_date(self.archive1))

    def test_cleanup(self):
        self.lastread.cleanup()
        self.assertFalse(self.lastread.enabled)
        self.assertTrue(os.path.isfile(self.db))

        # Closing twice shouldn't lead to exception
        self.lastread.cleanup()

    def test_reopen(self):
        self.lastread.set_page(self.archive1, 1)
        self.lastread.set_page(self.archive2, 2)
        self.assertEqual(1, self.lastread.get_page(self.archive1))
        self.assertEqual(2, self.lastread.get_page(self.archive2))

        self.lastread.cleanup()

# Path: mcomix/last_read_page.py
# class LastReadPage(object):
#     def __init__(self, dbfile):
#     def cleanup(self):
#     def set_enabled(self, enabled):
#     def count(self):
#     def set_page(self, path, page):
#     def clear_page(self, path):
#     def clear_all(self):
#     def get_page(self, path):
#     def get_date(self, path):
#     def _init_database(self, dbfile):


# Path: test/open_last_page.py
import unittest
import tempfile
import os
from mcomix import last_read_page


    def test_nonexistant_file(self):
        self.assertRaises(ValueError, self.lastread.set_page,
            '/root/mcomix/file-that-should-not-exist-hopefully', 1)

    def test_invalid_page(self):
        self.assertRaises(ValueError, self.lastread.set_page,
            self.archive1, 0)
        self.assertRaises(ValueError, self.lastread.set_page,
            self.archive1, -1)

    def test_date(self):
        self.lastread.set_page(self.archive1, 1)
        self.assertIsNotNone(self.lastread.get_date(self.archive1))

    def test_cleanup(self):
        self.lastread.cleanup()
        self.assertFalse(self.lastread.enabled)
        self.assertTrue(os.path.isfile(self.db))

        # Closing twice shouldn't lead to exception
        self.lastread.cleanup()

    def test_reopen(self):
        self.lastread.set_page(self.archive1, 1)
        self.lastread.set_page(self.archive2, 2)
        self.assertEqual(1, self.lastread.get_page(self.archive1))
        self.assertEqual(2, self.lastread.get_page(self.archive2))

        self.lastread.cleanup()

        self.lastread = last_read_page.LastReadPage(self.db)