1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-11-14 12:42:27 +00:00
senpy/tests/test_plugins.py

73 lines
1.9 KiB
Python
Raw Normal View History

#!/bin/env python
2015-11-05 17:50:37 +00:00
import os
import logging
import pickle
import shutil
import tempfile
2015-11-05 17:50:37 +00:00
import json
import os
from unittest import TestCase
from senpy.models import Results, Entry
2015-11-05 17:50:37 +00:00
from senpy.plugins import SenpyPlugin, ShelfMixin
2015-12-11 13:53:30 +00:00
class ShelfTest(ShelfMixin, SenpyPlugin):
def test(self, key=None, value=None):
assert key in self.sh
print('Checking: sh[{}] == {}'.format(key, value))
print('SH[{}]: {}'.format(key, self.sh[key]))
assert self.sh[key] == value
2015-11-05 17:50:37 +00:00
class ModelsTest(TestCase):
2015-12-11 13:53:30 +00:00
def tearDown(self):
if os.path.exists(self.shelf_dir):
shutil.rmtree(self.shelf_dir)
2015-12-11 13:53:30 +00:00
if os.path.isfile(self.shelf_file):
os.remove(self.shelf_file)
2015-11-05 17:50:37 +00:00
def setUp(self):
self.shelf_dir = tempfile.mkdtemp()
self.shelf_file = os.path.join(self.shelf_dir, "shelf")
2015-11-05 17:50:37 +00:00
def test_shelf(self):
2015-12-11 13:53:30 +00:00
''' A shelf is created and the value is stored '''
a = ShelfTest(info={'name': 'shelve',
'version': 'test',
'shelf_file': self.shelf_file})
assert a.sh == {}
assert a.shelf_file == self.shelf_file
a.sh['a'] = 'fromA'
a.test(key='a', value='fromA')
a.save()
sh = pickle.load(open(self.shelf_file, 'rb'))
2015-12-11 13:53:30 +00:00
assert sh['a'] == 'fromA'
def test_two(self):
''' Reusing the values of a previous shelf '''
a = ShelfTest(info={'name': 'shelve',
'version': 'test',
'shelf_file': self.shelf_file})
print('Shelf file: %s' % a.shelf_file)
a.sh['a'] = 'fromA'
a.save()
2015-12-11 13:53:30 +00:00
b = ShelfTest(info={'name': 'shelve',
'version': 'test',
'shelf_file': self.shelf_file})
b.test(key='a', value='fromA')
b.sh['a'] = 'fromB'
assert b.sh['a'] == 'fromB'