Ejemplo n.º 1
0
 def test_pickled_file(self):
     o = TestObj()
     o.foo = 42
     picklejar().add('o1', (1, ), o)
     o2 = picklejar().get('o1', (1, ))
     self.assertIsNotNone(o2)
     self.assertEqual(42, o2.foo)
Ejemplo n.º 2
0
 def test_no_cache(self):
     current_cache_directory = picklejarfactory.cache_directory
     picklejarfactory.cache_directory = None
     o = picklejar().get('cls', (1, ))
     self.assertIsNone(o)
     o1 = TestObj()
     o1.foo = "bagels"
     picklejar().add('o1', (2, 3), o1)
     ot1 = picklejar().get('o1', (2, 3))
     self.assertIsNone(ot1)
     picklejarfactory.cache_directory = current_cache_directory
     o = picklejar().get('cls', (1, ))
     self.assertEqual("CLASS", o.cls)
Ejemplo n.º 3
0
 def __init__(self,
              mv_file_loc: str = "http://hl7.org/FHIR/fhir.ttl",
              fmt: str = "turtle",
              cache_mv_file=True):
     """
     Load a FHIR Metadata Vocabulary image
     :param mv_file_loc: file name or URI of fhir.ttl image
     :param fmt: format of image
     :param cache_mv_file: True means cache an image in ~/.cache/.  False means no cache
     """
     self.g = picklejar().get(
         mv_file_loc, signature(mv_file_loc)) if cache_mv_file else None
     if not self.g:
         self.from_cache = False
         self.g = Graph()
         self.g.load(mv_file_loc, format=fmt)
         if cache_mv_file:
             picklejar().add(mv_file_loc, signature(mv_file_loc), self.g)
     else:
         self.from_cache = True
Ejemplo n.º 4
0
 def test_cache_loc(self):
     current_cache_directory = picklejarfactory.cache_directory
     test_directory = os.path.join(
         os.path.split(os.path.abspath(__file__))[0], 'data')
     picklejarfactory.cache_directory = os.path.abspath(
         os.path.join(test_directory, 'pjcache'))
     make_and_clear_directory(picklejarfactory.cache_directory)
     o1 = TestObj()
     o1.foo = "bagels"
     picklejar().add('o1', (2, 3), o1)
     o2 = TestObj()
     o2.foo = "cheese"
     picklejar().add('o2', (2, 5), o2)
     ot1 = picklejar().get('o1', (2, 3))
     ot2 = picklejar().get('o2', (2, 5))
     self.assertEqual("bagels", ot1.foo)
     self.assertEqual("cheese", ot2.foo)
     picklejar().clear()
     picklejarfactory.cache_directory = current_cache_directory
     ot1 = picklejar().get('o1', (2, 3))
     ot2 = picklejar().get('o2', (2, 5))
     self.assertIsNone(ot1)
     self.assertIsNone(ot2)
     self.assertIsNotNone(picklejar().get('cls', (1, )))
Ejemplo n.º 5
0
 def test_singleton(self):
     o = picklejar().get('cls', (1, ))
     self.assertIsNotNone(o)
     self.assertEqual("CLASS", o.cls)
Ejemplo n.º 6
0
 def tearDownClass(cls):
     picklejar().clear()
Ejemplo n.º 7
0
 def setUpClass(cls):
     picklejar().clear()
     cls.current_cache_directory = picklejarfactory.cache_directory
     o = TestObj()
     o.cls = "CLASS"
     picklejar().add("cls", (1, ), o)