#!/usr/bin/python
# File:        level.py
# Description: level
# Created:     2017-06-28


import unittest
import sys

if '../' not in sys.path:
    sys.path.append('../')

from distance.level import Level
from distance.bytes import DstBytes, UnexpectedEOFError


class LevelTest(unittest.TestCase):

    def test_level(self):
        with open("in/level/test-straightroad.bytes", 'rb') as f:
            dbytes = DstBytes(f)
            level = Level(dbytes)
            self.assertEqual(level.level_name, "Test-straightroad")

    def test_truncated(self):
        with open("in/level/test-straightroad_truncated.bytes", 'rb') as f:
            dbytes = DstBytes(f)
            level = Level(dbytes)
            self.assertEqual(level.level_name, "Test-straightroad")
            results = [level.read_settings()] + list(level.iter_objects())
            self.assertEqual(len(results), 3)

    def test_truncated2(self):
        with open("in/level/test-straightroad_truncated_2.bytes", 'rb') as f:
            dbytes = DstBytes(f)
            level = Level(dbytes)
            self.assertEqual(level.level_name, "Test-straightroad")
            gen = level.iter_objects()
            obj, sane, exc = level.read_settings()
            obj, sane, exc = next(gen)
            with self.assertRaises(UnexpectedEOFError):
                raise AssertionError(next(gen))


# vim:set sw=4 ts=8 sts=4 et sr ft=python fdm=marker tw=0:

@@ -235,16 +235,30 @@
 stBytes,
+ PrintContext,
  Unexpec
@@ -269,16 +269,16 @@
 OFError%0A
-
 %0A%0Aclass 
@@ -404,41 +404,8 @@
  f:%0A
-            dbytes = DstBytes(f)%0A
     
@@ -418,38 +418,43 @@
   level = Level(
-db
+DstB
 ytes
+(f)
 )%0A            se
@@ -508,16 +508,198 @@
 road%22)%0A%0A
+    def test_print_data(self):%0A        p = PrintContext.for_test()%0A        with open(%22in/level/test-straightroad.bytes%22, 'rb') as f:%0A            p.print_data_of(Level(DstBytes(f)))%0A%0A
     def 

add test for Level.print_data