Beispiel #1
0
    def test_json_get(self):
        # we fail if file doesn't exist
        os.unlink(self.tmpfile)
        with self.assertRaises(OSError):
            concurrently.json_get(self.tmpfile, False)

        # we can also pass if requested
        os.unlink(self.tmpfile)
        self.assertEqual({}, concurrently.json_get(self.tmpfile, True))

        # we can read a good file
        concurrently.json_create(self.tmpfile, {'key': 'val'})
        data = concurrently.json_get(self.tmpfile)
        self.assertEqual('val', data['key'])
Beispiel #2
0
    def test_json_get(self):
        # we fail if file doesn't exist
        os.unlink(self.tmpfile)
        with self.assertRaises(OSError):
            concurrently.json_get(self.tmpfile, False)

        # we can also pass if requested
        os.unlink(self.tmpfile)
        self.assertEqual({}, concurrently.json_get(self.tmpfile, True))

        # we can read a good file
        concurrently.json_create(self.tmpfile, {'key': 'val'})
        data = concurrently.json_get(self.tmpfile)
        self.assertEqual('val', data['key'])
Beispiel #3
0
    def test_json_data(self):
        os.unlink(self.tmpfile)
        concurrently.json_create(self.tmpfile, {'key': 'val'})

        with concurrently.json_data(self.tmpfile) as d:
            self.assertEqual(d['key'], 'val')
            d['key'] = 'updated'
        self.assertEqual('updated', concurrently.json_get(self.tmpfile)['key'])
Beispiel #4
0
    def test_json_data(self):
        os.unlink(self.tmpfile)
        concurrently.json_create(self.tmpfile, {'key': 'val'})

        with concurrently.json_data(self.tmpfile) as d:
            self.assertEqual(d['key'], 'val')
            d['key'] = 'updated'
        self.assertEqual('updated', concurrently.json_get(self.tmpfile)['key'])