# Path: spykeutils/tools.py
#     HAS_DESCRIPTION = True
#     HAS_DESCRIPTION = False
# def apply_to_dict(fn, dictionary, *args):
# def bin_spike_trains(trains, sampling_rate, t_start=None, t_stop=None):
# def _bin_single_spike_train(train, bins):
# def concatenate_spike_trains(trains):
# def minimum_spike_train_interval(
#         trains, t_start=-sp.inf * pq.s, t_stop=sp.inf * pq.s):
# def maximum_spike_train_interval(
#         trains, t_start=sp.inf * pq.s, t_stop=-sp.inf * pq.s):
# def _handle_orphans(obj, remove):
# def remove_from_hierarchy(obj, remove_half_orphans=True):
# def extract_spikes(train, signals, length, align_time):


    import unittest2 as ut
    import unittest as ut
import neo
import neo.io.tools
import neo.test.tools
import quantities as pq
import scipy as sp
from builders import arange_spikes
from numpy.testing import assert_array_equal, assert_array_almost_equal
from spykeutils import tools
            b.create_many_to_one_relationship()
        return b

    def test_remove_block(self):
        block = self.create_hierarchy(False)
        comp = self.create_hierarchy(False)
        tools.remove_from_hierarchy(block)

        neo.test.tools.assert_same_sub_schema(block, comp)

    def test_remove_segment_no_orphans(self):
        block = self.create_hierarchy(False)
        comp = self.create_hierarchy(False)

        seg = block.segments[1]
        tools.remove_from_hierarchy(seg)

        self.assertFalse(seg in block.segments)
        self.assertEqual(len(block.list_units),
                         self.UNITS * self.CHANNEL_GROUPS)
        for u in block.list_units:
            self.assertEqual(len(u.spikes), self.SEGMENTS - 1)
            self.assertEqual(len(u.spiketrains), self.SEGMENTS - 1)
        neo.test.tools.assert_same_sub_schema(seg, comp.segments[1])

    def test_remove_segment_keep_orphans(self):
        block = self.create_hierarchy(False)
        comp = self.create_hierarchy(False)

        seg = block.segments[1]

# Path: spykeutils/tools.py
#     HAS_DESCRIPTION = True
#     HAS_DESCRIPTION = False
# def apply_to_dict(fn, dictionary, *args):
# def bin_spike_trains(trains, sampling_rate, t_start=None, t_stop=None):
# def _bin_single_spike_train(train, bins):
# def concatenate_spike_trains(trains):
# def minimum_spike_train_interval(
#         trains, t_start=-sp.inf * pq.s, t_stop=sp.inf * pq.s):
# def maximum_spike_train_interval(
#         trains, t_start=sp.inf * pq.s, t_stop=-sp.inf * pq.s):
# def _handle_orphans(obj, remove):
# def remove_from_hierarchy(obj, remove_half_orphans=True):
# def extract_spikes(train, signals, length, align_time):


# Path: spykeutils/tests/test_tools.py
    import unittest2 as ut
    import unittest as ut
import neo
import neo.io.tools
import neo.test.tools
import quantities as pq
import scipy as sp
from builders import arange_spikes
from numpy.testing import assert_array_equal, assert_array_almost_equal
from spykeutils import tools

            b.create_many_to_one_relationship()
        return b

    def test_remove_block(self):
        block = self.create_hierarchy(False)
        comp = self.create_hierarchy(False)
        tools.remove_from_hierarchy(block)

        neo.test.tools.assert_same_sub_schema(block, comp)

    def test_remove_segment_no_orphans(self):
        block = self.create_hierarchy(False)
        comp = self.create_hierarchy(False)

        seg = block.segments[1]
        tools.remove_from_hierarchy(seg)

        self.assertFalse(seg in block.segments)
        self.assertEqual(len(block.list_units),
                         self.UNITS * self.CHANNEL_GROUPS)
        for u in block.list_units:
            self.assertEqual(len(u.spikes), self.SEGMENTS - 1)
            self.assertEqual(len(u.spiketrains), self.SEGMENTS - 1)
        neo.test.tools.assert_same_sub_schema(seg, comp.segments[1])

    def test_remove_segment_keep_orphans(self):
        block = self.create_hierarchy(False)
        comp = self.create_hierarchy(False)

        seg = block.segments[1]

        tools.remove_from_hierarchy(seg, False)