# Path: g_sorcery/g_collections.py
# class serializable_elist(object):
#     """
#     A JSON serializable version of elist.
#     """
# 
#     __slots__ = ('data')
# 
#     def __init__(self, iterable=None, separator=' '):
#         '''
#         iterable: initialize from iterable's items
#         separator: string used to join list members with for __str__()
#         '''
#         self.data = elist(iterable or [], separator)
# 
#     def __eq__(self, other):
#         return self.data == other.data
# 
#     def __iter__(self):
#         return iter(self.data)
# 
#     def __str__(self):
#         '''Custom output function
#         '''
#         return str(self.data)
# 
#     def append(self, x):
#         self.data.append(x)
# 
#     def serialize(self):
#         return {"separator": self.data._sep_, "data" : self.data}
# 
#     @classmethod
#     def deserialize(cls, value):
#         return serializable_elist(value["data"], separator = value["separator"])
# 
# Path: tests/base.py
# class BaseTest(unittest.TestCase):
# 
#     def setUp(self):
#         self.tempdir = TemporaryDirectory()
# 
#     def tearDown(self):
#         del self.tempdir
# 
# Path: tests/serializable.py
# class NonSerializableClass(object):
#     pass
# 
# class SerializableClass(object):
# 
#     __slots__ = ("field1", "field2")
# 
#     def __init__(self, field1, field2):
#         self.field1 = field1
#         self.field2 = field2
# 
#     def __eq__(self, other):
#         return self.field1 == other.field1 \
#           and self.field2 == other.field2
# 
#     def serialize(self):
#         return {"field1": self.field1, "field2": self.field2}
# 
# class DeserializableClass(SerializableClass):
# 
#     @classmethod
#     def deserialize(cls, value):
#         return DeserializableClass(value["field1"], value["field2"])


import os
import unittest
from g_sorcery.g_collections import serializable_elist
from tests.base import BaseTest
from tests.serializable import NonSerializableClass, SerializableClass, DeserializableClass
    from g_sorcery.file_bson.file_bson import FileBSON
            super(TestFileJSON, self).setUp()
            self.directory = os.path.join(self.tempdir.name, 'tst')
            self.name = 'tst.json'
            self.path = os.path.join(self.directory, self.name)

        def test_write_read(self):
            fj = FileBSON(self.directory, self.name, ["mandatory"])
            content = {"mandatory":"1", "test":"2"}
            fj.write(content)
            content_r = fj.read()
            self.assertEqual(content, content_r)

        def test_serializable(self):
            fj = FileBSON(self.directory, self.name, [])
            content = SerializableClass("1", "2")
            fj.write(content)
            content_r = fj.read()
            self.assertEqual(content_r, {"field1":"1", "field2":"2"})
            self.assertRaises(TypeError, fj.write, NonSerializableClass())

        def test_deserializable(self):
            fj = FileBSON(self.directory, self.name, [])
            content = DeserializableClass("1", "2")
            fj.write(content)
            content_r = fj.read()
            self.assertEqual(content, content_r)

        def test_deserializable_collection(self):
            fj = FileBSON(self.directory, self.name, [])
            content1 = DeserializableClass("1", "2")

# Path: g_sorcery/g_collections.py
# class serializable_elist(object):
#     """
#     A JSON serializable version of elist.
#     """
# 
#     __slots__ = ('data')
# 
#     def __init__(self, iterable=None, separator=' '):
#         '''
#         iterable: initialize from iterable's items
#         separator: string used to join list members with for __str__()
#         '''
#         self.data = elist(iterable or [], separator)
# 
#     def __eq__(self, other):
#         return self.data == other.data
# 
#     def __iter__(self):
#         return iter(self.data)
# 
#     def __str__(self):
#         '''Custom output function
#         '''
#         return str(self.data)
# 
#     def append(self, x):
#         self.data.append(x)
# 
#     def serialize(self):
#         return {"separator": self.data._sep_, "data" : self.data}
# 
#     @classmethod
#     def deserialize(cls, value):
#         return serializable_elist(value["data"], separator = value["separator"])
# 
# Path: tests/base.py
# class BaseTest(unittest.TestCase):
# 
#     def setUp(self):
#         self.tempdir = TemporaryDirectory()
# 
#     def tearDown(self):
#         del self.tempdir
# 
# Path: tests/serializable.py
# class NonSerializableClass(object):
#     pass
# 
# class SerializableClass(object):
# 
#     __slots__ = ("field1", "field2")
# 
#     def __init__(self, field1, field2):
#         self.field1 = field1
#         self.field2 = field2
# 
#     def __eq__(self, other):
#         return self.field1 == other.field1 \
#           and self.field2 == other.field2
# 
#     def serialize(self):
#         return {"field1": self.field1, "field2": self.field2}
# 
# class DeserializableClass(SerializableClass):
# 
#     @classmethod
#     def deserialize(cls, value):
#         return DeserializableClass(value["field1"], value["field2"])


# Path: tests/test_FileBSON.py
import os
import unittest
from g_sorcery.g_collections import serializable_elist
from tests.base import BaseTest
from tests.serializable import NonSerializableClass, SerializableClass, DeserializableClass
    from g_sorcery.file_bson.file_bson import FileBSON

            super(TestFileJSON, self).setUp()
            self.directory = os.path.join(self.tempdir.name, 'tst')
            self.name = 'tst.json'
            self.path = os.path.join(self.directory, self.name)

        def test_write_read(self):
            fj = FileBSON(self.directory, self.name, ["mandatory"])
            content = {"mandatory":"1", "test":"2"}
            fj.write(content)
            content_r = fj.read()
            self.assertEqual(content, content_r)

        def test_serializable(self):
            fj = FileBSON(self.directory, self.name, [])
            content = SerializableClass("1", "2")
            fj.write(content)
            content_r = fj.read()
            self.assertEqual(content_r, {"field1":"1", "field2":"2"})
            self.assertRaises(TypeError, fj.write, NonSerializableClass())

        def test_deserializable(self):
            fj = FileBSON(self.directory, self.name, [])
            content = DeserializableClass("1", "2")
            fj.write(content)
            content_r = fj.read()
            self.assertEqual(content, content_r)

        def test_deserializable_collection(self):
            fj = FileBSON(self.directory, self.name, [])
            content1 = DeserializableClass("1", "2")

            content2 = DeserializableClass("3", "4")