#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function, absolute_import

"""
test_flatson
----------------------------------

Tests for `flatson` module.
"""

import json
import os
import skinfer
import unittest

from flatson import Flatson
import tempfile


EMPTY_SCHEMA = skinfer.generate_schema({})

SIMPLE_SCHEMA = skinfer.generate_schema({'a_prop': ''})

LIST_SCHEMA = skinfer.generate_schema([])

SAMPLE_WITH_LIST_OF_OBJECTS = {
    'first': 'hello',
    'list': [{'key1': 'value1', 'key2': 'value2'}, {'key1': 'value3', 'key2': 'value4'}]
}

SAMPLE_WITH_LIST_OF_TUPLES = {
    'first': 'hello',
    'list': [['value1', 'value2'], ['value3', 'value4']]
}


class TestFlatson(unittest.TestCase):
    def test_create(self):
        f = Flatson(schema=SIMPLE_SCHEMA)
        assert f.schema == SIMPLE_SCHEMA

    def test_create_from_schemafile(self):
        _, fname = tempfile.mkstemp()
        try:
            with open(fname, 'w') as f:
                json.dump(SIMPLE_SCHEMA, f)

            obj = Flatson.from_schemafile(fname)
            self.assertEquals(SIMPLE_SCHEMA, obj.schema)
        finally: