# Path: distance/_level.py
# class Level(Fragment):
# 
#     class_tag = 'Level'
#     default_container = Section(Magic[9])
# 
#     layers = ()
#     name = None
#     version = 3
# 
#     def _read_section_data(self, dbytes, sec):
#         if sec.magic != Magic[9]:
#             raise ValueError(f"Unexpected section: {sec.magic}")
#         self.name = sec.name
#         self.version = sec.version
# 
#         num_layers = sec.count
# 
#         self.content = self.classes.level_content.lazy_n_maybe(
#             dbytes, num_layers + 1)
#         if num_layers:
#             self.layers = LazySequence(
#                 (obj for obj in self.content if obj.class_tag == 'Layer'),
#                 num_layers)
# 
#     def _get_write_section(self, sec):
#         return Section(Magic[9], self.name, len(self.layers), self.version)
# 
#     def _visit_write_section_data(self, dbytes, sec):
#         if sec.magic != Magic[9]:
#             raise ValueError(f"Unexpected section: {sec.magic}")
#         for obj in self.content:
#             yield obj.visit_write(dbytes)
# 
#     @property
#     def settings(self):
#         try:
#             return self._settings
#         except AttributeError:
#             for obj in self.content:
#                 if obj.class_tag != 'Layer':
#                     s = obj
#                     break
#             else:
#                 s = None
#             self._settings = s
#             return s
# 
#     @settings.setter
#     def settings(self, s):
#         self._settings = s
# 
#     def _repr_detail(self):
#         supstr = super()._repr_detail()
#         if self.name:
#             return f" {self.name!r}{supstr}"
#         return supstr
# 
#     def visit_print(self, p):
#         with need_counters(p) as counters:
#             yield super().visit_print(p)
#             if counters:
#                 counters.print(p)
# 
#     def _print_type(self, p):
#         p(f"Level: {self.name!r} version {self.version}")
# 
#     def _visit_print_data(self, p):
#         yield super()._visit_print_data(p)
#         p(f"Level name: {self.name!r}")
# 
#     def _visit_print_children(self, p):
#         if self.settings is not None:
#             with p.tree_children(1):
#                 yield self.settings.visit_print(p)
#         for layer in self.layers:
#             yield layer.visit_print(p)
# 
# Path: distance/filter/unkill.py
# class UnkillFilter(ObjectFilter):
# 
#     @classmethod
#     def add_args(cls, parser):
#         super().add_args(parser)
#         parser.add_argument(":debug", action='store_true')
#         parser.add_argument(":nocolor", dest='color',
#                             action='store_false',
#                             help="Use default kill grid color.")
#         parser.add_argument(":color", dest='color',
#                             action='store_true',
#                             help="Copy kill grid color (default).")
#         parser.add_argument(":collision", dest='collision',
#                             action='store_true', default=True,
#                             help="Enable simples collision (default).")
#         parser.add_argument(":nocollision", dest='collision',
#                             action='store_false',
#                             help="Disable simples collision.")
# 
#     def __init__(self, args):
#         super().__init__(args)
#         self.collision = args.collision
#         self.debug = args.debug
#         self.color = args.color
#         self.num_replaced = 0
# 
#     def filter_object(self, obj):
#         try:
#             mapper = KILLGRID_MAPPERS[obj.type]
#         except KeyError:
#             return obj,
#         try:
#             result = mapper.apply(obj, collision=self.collision,
#                                   copy_color=self.color)
#         except DoNotApply:
#             return obj,
#         self.num_replaced += 1
#         if self.debug:
#             return tuple(result) + (obj,)
#         return result
# 
#     def print_summary(self, p):
#         p(f"Replaced kill grids: {self.num_replaced}")


from argparse import Namespace
from distance import Level
from distance.filter import UnkillFilter
import unittest



def mkargs(maxrecurse=-1, collision=True, color=True, debug=False):
    return Namespace(**locals())


class UnkillTest(unittest.TestCase):

    def test_replace(self):

# Path: distance/_level.py
# class Level(Fragment):
# 
#     class_tag = 'Level'
#     default_container = Section(Magic[9])
# 
#     layers = ()
#     name = None
#     version = 3
# 
#     def _read_section_data(self, dbytes, sec):
#         if sec.magic != Magic[9]:
#             raise ValueError(f"Unexpected section: {sec.magic}")
#         self.name = sec.name
#         self.version = sec.version
# 
#         num_layers = sec.count
# 
#         self.content = self.classes.level_content.lazy_n_maybe(
#             dbytes, num_layers + 1)
#         if num_layers:
#             self.layers = LazySequence(
#                 (obj for obj in self.content if obj.class_tag == 'Layer'),
#                 num_layers)
# 
#     def _get_write_section(self, sec):
#         return Section(Magic[9], self.name, len(self.layers), self.version)
# 
#     def _visit_write_section_data(self, dbytes, sec):
#         if sec.magic != Magic[9]:
#             raise ValueError(f"Unexpected section: {sec.magic}")
#         for obj in self.content:
#             yield obj.visit_write(dbytes)
# 
#     @property
#     def settings(self):
#         try:
#             return self._settings
#         except AttributeError:
#             for obj in self.content:
#                 if obj.class_tag != 'Layer':
#                     s = obj
#                     break
#             else:
#                 s = None
#             self._settings = s
#             return s
# 
#     @settings.setter
#     def settings(self, s):
#         self._settings = s
# 
#     def _repr_detail(self):
#         supstr = super()._repr_detail()
#         if self.name:
#             return f" {self.name!r}{supstr}"
#         return supstr
# 
#     def visit_print(self, p):
#         with need_counters(p) as counters:
#             yield super().visit_print(p)
#             if counters:
#                 counters.print(p)
# 
#     def _print_type(self, p):
#         p(f"Level: {self.name!r} version {self.version}")
# 
#     def _visit_print_data(self, p):
#         yield super()._visit_print_data(p)
#         p(f"Level name: {self.name!r}")
# 
#     def _visit_print_children(self, p):
#         if self.settings is not None:
#             with p.tree_children(1):
#                 yield self.settings.visit_print(p)
#         for layer in self.layers:
#             yield layer.visit_print(p)
# 
# Path: distance/filter/unkill.py
# class UnkillFilter(ObjectFilter):
# 
#     @classmethod
#     def add_args(cls, parser):
#         super().add_args(parser)
#         parser.add_argument(":debug", action='store_true')
#         parser.add_argument(":nocolor", dest='color',
#                             action='store_false',
#                             help="Use default kill grid color.")
#         parser.add_argument(":color", dest='color',
#                             action='store_true',
#                             help="Copy kill grid color (default).")
#         parser.add_argument(":collision", dest='collision',
#                             action='store_true', default=True,
#                             help="Enable simples collision (default).")
#         parser.add_argument(":nocollision", dest='collision',
#                             action='store_false',
#                             help="Disable simples collision.")
# 
#     def __init__(self, args):
#         super().__init__(args)
#         self.collision = args.collision
#         self.debug = args.debug
#         self.color = args.color
#         self.num_replaced = 0
# 
#     def filter_object(self, obj):
#         try:
#             mapper = KILLGRID_MAPPERS[obj.type]
#         except KeyError:
#             return obj,
#         try:
#             result = mapper.apply(obj, collision=self.collision,
#                                   copy_color=self.color)
#         except DoNotApply:
#             return obj,
#         self.num_replaced += 1
#         if self.debug:
#             return tuple(result) + (obj,)
#         return result
# 
#     def print_summary(self, p):
#         p(f"Replaced kill grids: {self.num_replaced}")


# Path: tests/filter/test_unkill.py
from argparse import Namespace
from distance import Level
from distance.filter import UnkillFilter
import unittest




def mkargs(maxrecurse=-1, collision=True, color=True, debug=False):
    return Namespace(**locals())


class UnkillTest(unittest.TestCase):

    def test_replace(self):

        l = Level("tests/in/level/finite grids.bytes")