Exemplo n.º 1
0
    def runTest(self):
        spec = mm.loader.StorageSpec(DATA_VERSION, FILE_PATH)
        spec2 = mm.loader.StorageSpec(DATA_VERSION+1, FILE_PATH)

        if os.path.exists(spec.path):
            os.unlink(spec.path)

        if os.path.exists(spec2.path):
            os.unlink(spec2.path)

        self.assertFalse(os.path.exists(spec.path))

        loader = mm.loader.Loader(make_data, spec)
            
        self.assertEqual(loader.load(), None)

        value = loader.get()
        self.assertEqual(make_data(), value)
        self.assertTrue(os.path.exists(spec.path))

        loader = mm.loader.Loader(make_data, spec)
        self.assertEqual(loader.load(), value)

        self.assertTrue(os.path.exists(spec.path))
        loader = mm.loader.Loader(make_data, spec2)
        self.assertEqual(loader.load(), None)
        self.assertFalse(os.path.exists(spec2.path))

        if os.path.exists(spec.path):
            os.unlink(spec.path)

        if os.path.exists(spec2.path):
            os.unlink(spec2.path)
Exemplo n.º 2
0
    def runTest(self):
        for p in glob.glob(PICKLE_PATH + '.v1.pickle*'):
            os.remove(p)

        loader = mm.loader.Loader(PickledSingleton, PICKLE_SPEC)
        s = loader.get()

        # corrupt the file.
        os.remove(loader.path)
        with open(loader.path, 'w+') as fp:
            fp.write('x')

        PickledSingleton.clear()

        ss = loader.get()
        self.assertNotEqual(s.special_value, ss.special_value)

        PickledSingleton.clear()

        sss = PickledSingleton()
        self.assertNotEqual(ss.special_value, sss.special_value)

        ssss = PickledSingleton()



        self.assertEqual(sss.special_value, ssss.special_value)
        self.assertIs(sss, ssss)

        loader.store(s)
        loader.store(ss)
        loader.store(sss)

        self.assertTrue(os.path.exists(loader.path))
        self.assertTrue(os.path.exists(loader.path + '.1'))
        self.assertTrue(os.path.exists(loader.path + '.2'))
        self.assertTrue(os.path.exists(loader.path + '.3'))