# Path: tests/ex03_company/models.py
# class Company(object):
#     name = related.StringField()
#     uuid = related.UUIDField()
#     email = related.RegexField("[^@]+@[^@]+", required=False)
#     is_active = related.BooleanField(required=False)
#     url = related.URLField(required=False)
#     meta = related.ChildField(dict, required=False)
#     nicknames = related.SequenceField(str, required=False)
#     temperature = related.FloatField(required=False)
#     guess = related.SetField(int, required=False)
#     established = related.DateField('%m/%d/%Y', required=False)
#     closed = related.DateField(required=False)  # default formatter (%Y-%m-%d)


from datetime import date, datetime
from uuid import UUID
from future.moves.urllib.parse import ParseResult
from pytest import fixture, raises
from six import string_types
from related import (to_dict, to_yaml, from_yaml,
                     to_json, from_json)
from .models import Company
    assert company_dict['name'] == 'Acme Inc.'
    assert isinstance(company_dict['uuid'], string_types)
    assert isinstance(company_dict['url'], string_types)
    assert company_dict['established'] == "01/02/1903"
    assert company_dict['closed'] == "1904-05-06"


def test_yaml(company):
    company_yaml = to_yaml(to_dict(company))
    assert ("uuid: %s" % company.uuid) in company_yaml
    assert ("url: %s" % company.url.geturl()) in company_yaml


def test_roundtrip_yaml(company):
    new_company = from_yaml(to_yaml(company), Company)
    assert new_company == company


def test_roundtrip_json(company):
    new_company = from_json(to_json(company), Company)
    assert new_company == company


def test_invalid_regex():
    with raises(TypeError):
        Company(name="fail", email="fail")


def test_invalid_boolean(company):
    with raises(TypeError):

# Path: tests/ex03_company/models.py
# class Company(object):
#     name = related.StringField()
#     uuid = related.UUIDField()
#     email = related.RegexField("[^@]+@[^@]+", required=False)
#     is_active = related.BooleanField(required=False)
#     url = related.URLField(required=False)
#     meta = related.ChildField(dict, required=False)
#     nicknames = related.SequenceField(str, required=False)
#     temperature = related.FloatField(required=False)
#     guess = related.SetField(int, required=False)
#     established = related.DateField('%m/%d/%Y', required=False)
#     closed = related.DateField(required=False)  # default formatter (%Y-%m-%d)


# Path: tests/ex03_company/test_company.py
from datetime import date, datetime
from uuid import UUID
from future.moves.urllib.parse import ParseResult
from pytest import fixture, raises
from six import string_types
from related import (to_dict, to_yaml, from_yaml,
                     to_json, from_json)
from .models import Company

    assert company_dict['name'] == 'Acme Inc.'
    assert isinstance(company_dict['uuid'], string_types)
    assert isinstance(company_dict['url'], string_types)
    assert company_dict['established'] == "01/02/1903"
    assert company_dict['closed'] == "1904-05-06"


def test_yaml(company):
    company_yaml = to_yaml(to_dict(company))
    assert ("uuid: %s" % company.uuid) in company_yaml
    assert ("url: %s" % company.url.geturl()) in company_yaml


def test_roundtrip_yaml(company):
    new_company = from_yaml(to_yaml(company), Company)
    assert new_company == company


def test_roundtrip_json(company):
    new_company = from_json(to_json(company), Company)
    assert new_company == company


def test_invalid_regex():
    with raises(TypeError):
        Company(name="fail", email="fail")


def test_invalid_boolean(company):
    with raises(TypeError):

        Company(name="fail", is_active="YES!")