shep/tests/test_file.py

43 lines
1.0 KiB
Python
Raw Normal View History

2022-01-31 16:53:33 +01:00
# standard imports
import unittest
import tempfile
import os
# local imports
from shep.persist import PersistedState
from shep.store.file import SimpleFileStoreFactory
from shep.error import (
StateExists,
StateInvalid,
)
class TestStateReport(unittest.TestCase):
def setUp(self):
self.d = tempfile.mkdtemp()
self.factory = SimpleFileStoreFactory(self.d)
self.states = PersistedState(self.factory.add, 4)
self.states.add('foo')
self.states.add('bar')
self.states.add('baz')
def test_add(self):
2022-02-01 08:01:57 +01:00
self.states.put('abcd', state=self.states.FOO, contents='baz')
2022-01-31 16:53:33 +01:00
fp = os.path.join(self.d, 'FOO', 'abcd')
f = open(fp, 'r')
v = f.read()
f.close()
2022-02-01 08:01:57 +01:00
self.assertEqual(v, 'baz')
2022-01-31 16:53:33 +01:00
def test_dup(self):
2022-02-01 08:01:57 +01:00
self.states.put('abcd', state=self.states.FOO)
2022-01-31 16:53:33 +01:00
with self.assertRaises(FileExistsError):
2022-02-01 08:01:57 +01:00
self.states.put('abcd', state=self.states.FOO)
2022-01-31 16:53:33 +01:00
if __name__ == '__main__':
unittest.main()