2020-02-03 17:25:54 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from benedict.dicts.io import IODict
|
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
|
|
class io_dict_test_case(unittest.TestCase):
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
dir_path = cls.output_path(filepath='')
|
|
|
|
shutil.rmtree(dir_path, ignore_errors=True)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def input_path(filepath):
|
|
|
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
return os.path.join(dir_path, 'input/{}'.format(filepath))
|
|
|
|
|
2020-02-03 18:01:28 +00:00
|
|
|
@staticmethod
|
|
|
|
def input_url(filepath):
|
|
|
|
return 'https://raw.githubusercontent.com/fabiocaccamo/python-benedict/master/tests/dicts/io/input/{}'.format(filepath)
|
|
|
|
|
2020-02-03 17:25:54 +00:00
|
|
|
@staticmethod
|
|
|
|
def output_path(filepath):
|
|
|
|
dir_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
return os.path.join(dir_path, 'output/{}'.format(filepath))
|
|
|
|
|
|
|
|
def assertFileExists(self, filepath):
|
|
|
|
self.assertTrue(os.path.isfile(filepath))
|
|
|
|
|
2020-09-09 14:47:25 +00:00
|
|
|
def test_init_with_key_value_list(self):
|
|
|
|
d = IODict(a='1', b='2', c='3')
|
|
|
|
self.assertEqual(d, {
|
|
|
|
'a': '1',
|
|
|
|
'b': '2',
|
|
|
|
'c': '3',
|
|
|
|
})
|
|
|
|
|
2020-02-03 17:25:54 +00:00
|
|
|
def test_init_with_invalid_data(self):
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
d = IODict('invalid json data')
|