File: open_last_page.py

package info (click to toggle)
mcomix 1.2.1mcomix3+git20200206-1
  • links: PTS
  • area: main
  • in suites: bullseye, sid
  • size: 6,604 kB
  • sloc: python: 17,232; xml: 52; sh: 11; makefile: 7
file content (103 lines) | stat: -rw-r--r-- 3,668 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-

import unittest
import tempfile
import os

from mcomix import constants
from mcomix import last_read_page
from mcomix.library import backend

class OpenLastPageBasicTest(unittest.TestCase):
    def setUp(self):
        # Database file
        fp, self.db = tempfile.mkstemp('.db', 'mcomix-test')
        os.close(fp)
        constants.LIBRARY_DATABASE_PATH = self.db

        # Dummy archive (files are checked for existance)
        self.archive1 = os.path.abspath(u'test/files/archives/01-ZIP-Normal.zip')
        self.archive2 = os.path.abspath(u'test/files/archives/02-TAR-Normal.tar')

        # Library backend
        self.backend = backend.LibraryBackend()

        self.lastread = last_read_page.LastReadPage(self.backend)
        self.lastread.set_enabled(True)

    def tearDown(self):
        self.backend.close()
        os.unlink(self.db)

    def test_init(self):
        self.assertEqual(0, self.lastread.count())

    def test_count(self):
        self.lastread.set_page(self.archive1, 1)
        self.assertEqual(1, self.lastread.count())
        self.lastread.set_page(self.archive2, 1)
        self.assertEqual(2, self.lastread.count())

    def test_set_last_page(self):
        self.lastread.set_page(self.archive1, 1)
        self.assertEqual(1, self.lastread.get_page(self.archive1))

    def test_multiple_archives(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))

    def test_clear_page(self):
        self.lastread.set_page(self.archive1, 1)
        self.lastread.clear_page(self.archive1)
        self.assertIsNone(self.lastread.get_page(self.archive1))

    def test_clear_all(self):
        self.lastread.set_page(self.archive1, 1)
        self.lastread.clear_all()
        self.assertEqual(0, self.lastread.count())

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

    def test_enabled(self):
        self.lastread.set_enabled(False)
        self.lastread.set_page(self.archive1, 1)
        self.assertIsNone(self.lastread.get_page(self.archive1))

    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_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.backend.close()
        self.backend = backend.LibraryBackend()
        self.lastread = last_read_page.LastReadPage(self.backend)
        self.lastread.set_enabled(True)

        self.assertEqual(1, self.lastread.get_page(self.archive1),
                'Page should be remembered after shutdown')
        self.assertEqual(2, self.lastread.get_page(self.archive2),
                'Page should be remembered after shutdown')

# vim: expandtab:sw=4:ts=4