'''
Created on Mar 23, 2017

@author: jvazquez
'''
import io
import logging
import unittest

import dxfgrabber

from helix.Services.dxf_helper import DXFHelper
from helix.models.dxf.dxf_error import OldDxfFormatException

logger = logging.getLogger()


class DxfLayerValidatorTest(unittest.TestCase):
    def test_finds_new_format(self):
        with open('test/fixtures/dxf/input_dual_tilt_96_cell.dxf',
                  'r', newline='') as file:
            dxf_file_contents = file.read()
        dxf = dxfgrabber.read(io.StringIO(dxf_file_contents, newline=None))
        dxf_helper = DXFHelper()
        dxf_helper.build_polygons(dxf.entities)
        is_new_format = dxf_helper.is_new_aurora_format()
        msg = "Expected new format true, got {}"\
            .format(dxf_helper.is_new_aurora_format())
        self.assertTrue(is_new_format, msg)

    def test_finds_old_format(self):
        with open('test/fixtures/dxf/input_old_dual_tilt_96_cell.dxf',
                  'r', newline='') as file:
            dxf_file_contents = file.read()
        dxf = dxfgrabber.read(io.StringIO(dxf_file_contents, newline=None))
        dxf_helper = DXFHelper()
        self.assertRaises(OldDxfFormatException,
                          dxf_helper.build_polygons,
                          dxf.entities)
