示例#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'])
示例#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'])
示例#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'])
示例#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'])