Esempio n. 1
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'])
Esempio n. 2
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'])
Esempio n. 3
0
    def test_create_json(self):
        '''we can create a json file'''

        # we fail if it already exists
        with self.assertRaises(OSError):
            concurrently.json_create(self.tmpfile, {})
        os.unlink(self.tmpfile)

        # we can create
        concurrently.json_create(self.tmpfile, {})
Esempio n. 4
0
    def test_create_json(self):
        '''we can create a json file'''

        # we fail if it already exists
        with self.assertRaises(OSError):
            concurrently.json_create(self.tmpfile, {})
        os.unlink(self.tmpfile)

        # we can create
        concurrently.json_create(self.tmpfile, {})
Esempio n. 5
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'])
Esempio n. 6
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'])