Esempio n. 1
0
    def test_open_content_when_already_opened(self):
        tree = FakeTree()
        tree._add_file(
            ('path', 'to', 'db', 'content'),
            testdata.dbfiledata('content-1'))

        content = datafile.get_unopened_content(tree, ('path', 'to', 'db'))
        content.open_and_lock_readonly()
        self.assertRaisesRegex(
            AssertionError, 'already open', content.open_and_lock_readonly)
Esempio n. 2
0
    def test_access_content_without_opening_it(self):
        tree = FakeTree()
        tree._add_file(
            ('path', 'to', 'db', 'content'),
            testdata.dbfiledata('content-1'))

        content = datafile.get_unopened_content(tree, ('path', 'to', 'db'))
        self.assertRaisesRegex(AssertionError, 'is not open', next, content)
        self.assertRaisesRegex(
            AssertionError, 'is not open',
            content.append_item, datafile.ItemSetting(b'key', b'value'))
Esempio n. 3
0
    def test_access_content_after_closing_it(self):
        tree = FakeTree()
        tree._add_file(
            ('path', 'to', 'db', 'content'),
            testdata.dbfiledata('content-1'))

        content = datafile.get_unopened_content(tree, ('path', 'to', 'db'))
        content.open_and_lock_readonly()
        item = next(content)
        self.assertEqual('magic', item.kind)
        self.assertEqual(b'ebakup content data', item.value)
        content.close()
        self.assertRaisesRegex(AssertionError, 'is not open', next, content)
        self.assertRaisesRegex(
            AssertionError, 'is not open',
            content.append_item, datafile.ItemSetting(b'key', b'value'))
Esempio n. 4
0
    def test_get_unopened_content(self):
        expect = StandardItemData()
        expect.load_content_1()
        tree = FakeTree()
        tree._add_file(
            ('path', 'to', 'db', 'content'),
            testdata.dbfiledata('content-1'))

        content = datafile.get_unopened_content(tree, ('path', 'to', 'db'))
        content.open_and_lock_readonly()
        self.assertEqual(6, len(expect.items))
        # Don't read to the end before closing, to test that
        # re-opening the file really starts at the beginning.
        self.assertItemSequence(expect.items[:4], content)
        content.close()
        content.open_and_lock_readonly()
        self.assertItemSequence(expect.items, content)
        self.assertRaises(StopIteration, next, content)
        self.assertRaises(StopIteration, next, content)
        self.assertRaises(StopIteration, next, content)
        content.close()
        self.assertCountEqual((), tree._files_modified)
Esempio n. 5
0
 def __init__(self, db):
     self._db = db
     self._dbfile = datafile.get_unopened_content(db._tree, db._path)
     self._read_file()
Esempio n. 6
0
    def test_get_and_open_content_when_it_does_not_exist(self):
        tree = FakeTree()
        tree._add_directory(('path', 'to', 'db'))

        content = datafile.get_unopened_content(tree, ('path', 'to', 'db'))
        self.assertRaises(FileNotFoundError, content.open_and_lock_readonly)