From cfe04620615e25e4885a0a92bfaeab80de520289 Mon Sep 17 00:00:00 2001 From: Benoit Coste Date: Fri, 19 Jul 2019 11:37:45 +0200 Subject: [PATCH] Remove all notions of morphology equality (#91) This is now handled in morph-tool --- binds/python/bind_immutable.cpp | 21 ----- binds/python/bind_misc.cpp | 12 --- binds/python/bind_mutable.cpp | 23 ----- binds/python/bind_vasculature.cpp | 13 --- include/morphio/morphology.h | 16 ---- include/morphio/mut/morphology.h | 15 --- include/morphio/mut/section.h | 10 -- include/morphio/section.h | 12 --- include/morphio/vasc/vasculature.h | 11 --- src/CMakeLists.txt | 1 - src/morphology.cpp | 10 -- src/mut/morphology.cpp | 10 -- src/mut/section.cpp | 10 -- src/section.cpp | 10 -- src/tools.cpp | 144 ----------------------------- src/vasc/vasculature.cpp | 12 --- tests/test_1_swc.py | 23 ++--- tests/test_2_neurolucida.py | 42 ++------- tests/test_4_immut.py | 14 --- tests/test_5_mut.py | 73 +-------------- tests/test_6_writers.py | 17 ++-- tests/test_7_modifiers.py | 2 +- 22 files changed, 25 insertions(+), 476 deletions(-) delete mode 100644 src/tools.cpp diff --git a/binds/python/bind_immutable.cpp b/binds/python/bind_immutable.cpp index c293cbeb4..7ef85a4f2 100644 --- a/binds/python/bind_immutable.cpp +++ b/binds/python/bind_immutable.cpp @@ -23,21 +23,6 @@ static void bind_immutable_module(py::module &m) { .def(py::init(), "filename"_a, "options"_a=morphio::enums::Option::NO_MODIFIER) .def(py::init()) - .def("__eq__", [](const morphio::Morphology& a, const morphio::Morphology& b) { - return a.operator==(b); - }, py::is_operator(), - "Are considered equal, 2 morphologies with the same:\n" - "- point vector\n" - "- diameter vector\n" - "- perimeter vector\n" - "- cell family\n" - "- section types\n" - "- topology (children/parent relationship)\n\n" - "Note: the soma types are NOT required to be equal") - .def("__ne__", [](const morphio::Morphology& a, const morphio::Morphology& b) { - return a.operator!=(b); - }, py::is_operator()) - .def(py::self != py::self) .def("as_mutable", [](const morphio::Morphology* morph) { return morphio::mut::Morphology(*morph); }) @@ -146,12 +131,6 @@ static void bind_immutable_module(py::module &m) { "Note: the soma surface computation depends on the soma type"); py::class_(m, "Section") - .def("__eq__", [](const morphio::Section& a, const morphio::Section& b) { - return a.operator==(b); - }, py::is_operator()) - .def("__ne__", [](const morphio::Section& a, const morphio::Section& b) { - return a.operator!=(b); - }, py::is_operator()) .def("__str__", [](const morphio::Section& section) { std::stringstream ss; ss << section; diff --git a/binds/python/bind_misc.cpp b/binds/python/bind_misc.cpp index ed15a6dd0..e1e7a107d 100644 --- a/binds/python/bind_misc.cpp +++ b/binds/python/bind_misc.cpp @@ -217,16 +217,4 @@ static void bind_misc(py::module &m) { "neuronal_section_ids"_a, "distances_to_section_start"_a, "diameters"_a); m.doc() = "pybind11 example plugin"; // optional module docstring - - - m.def("diff", static_cast(&morphio::diff), - "Perform a diff on 2 morphologies, returns True if items differ", "left"_a, "right"_a, "log_level"_a=morphio::enums::LogLevel::INFO); - m.def("diff", static_cast(&morphio::diff), - "Perform a diff on 2 sections, returns True if items differ", "left"_a, "right"_a, "log_level"_a=morphio::enums::LogLevel::INFO); - - m.def("diff", static_cast(&morphio::mut::diff), - "Perform a diff on 2 morphologies, returns True if items differ", "left"_a, "right"_a, "log_level"_a=morphio::enums::LogLevel::INFO); - m.def("diff", static_cast(&morphio::mut::diff), - "Perform a diff on 2 sections, returns True if items differ", "left"_a, "right"_a, "log_level"_a=morphio::enums::LogLevel::INFO); - } diff --git a/binds/python/bind_mutable.cpp b/binds/python/bind_mutable.cpp index 6c768e571..885d0454f 100644 --- a/binds/python/bind_mutable.cpp +++ b/binds/python/bind_mutable.cpp @@ -20,23 +20,6 @@ static void bind_mutable_module(py::module &m) { .def(py::init(), "morphology"_a, "options"_a=morphio::enums::Option::NO_MODIFIER) - .def("__eq__", [](const morphio::mut::Morphology& a, const morphio::mut::Morphology& b) { - return a.operator==(b); - }, py::is_operator(), - "Are considered equal, 2 morphologies with the same:\n" - "- root sections\n" - "- section topology\n" - "- cell family\n" - "For each section:" - "- same points\n" - "- same diameters\n" - "- same perimeters\n" - "- same type\n" - "Note: the soma types are NOT required to be equal") - .def("__ne__", [](const morphio::mut::Morphology& a, const morphio::mut::Morphology& b) { - return a.operator!=(b); - }, py::is_operator()) - // Cell sub-part accessors .def_property_readonly("sections", &morphio::mut::Morphology::sections, "Returns a list containing IDs of all sections. " @@ -226,12 +209,6 @@ static void bind_mutable_module(py::module &m) { "immutable_section"_a, "recursive"_a=false); py::class_>(m, "Section") - .def("__eq__", [](const morphio::mut::Section& a, const morphio::mut::Section& b) { - return a.operator==(b); - }, py::is_operator()) - .def("__ne__", [](const morphio::mut::Section& a, const morphio::mut::Section& b) { - return a.operator!=(b); - }, py::is_operator()) .def("__str__", [](const morphio::mut::Section& section) { std::stringstream ss; ss << section; diff --git a/binds/python/bind_vasculature.cpp b/binds/python/bind_vasculature.cpp index 6f12665ba..5a531f714 100644 --- a/binds/python/bind_vasculature.cpp +++ b/binds/python/bind_vasculature.cpp @@ -20,19 +20,6 @@ static void bind_vasculature(py::module &m) { .def(py::init(), "filename"_a) // .def(py::init()) - .def("__eq__", [](const morphio::vasculature::Vasculature& a, const morphio::vasculature::Vasculature& b) { - return a.operator==(b); - }, py::is_operator(), - "Are considered equal, 2 morphologies with the same:\n" - "- point vector\n" - "- diameter vector\n" - "- section types\n" - "- topology\n") - .def("__ne__", [](const morphio::vasculature::Vasculature& a, const morphio::vasculature::Vasculature& b) { - return a.operator!=(b); - }, py::is_operator()) - .def(py::self != py::self) - // .def("as_mutable", [](const morphio::vasculature::VasculatureMorphology* morph) { return morphio::mut::Morphology(*morph); }) .def_property_readonly("sections", &morphio::vasculature::Vasculature::sections, diff --git a/include/morphio/morphology.h b/include/morphio/morphology.h index f922e0e9d..5fb7a99d5 100644 --- a/include/morphio/morphology.h +++ b/include/morphio/morphology.h @@ -26,22 +26,6 @@ class Morphology Morphology(Morphology&&); Morphology& operator=(Morphology&&); - /** - Equality operator: - Are considered equal, 2 morphologies with the same: - - point vector - - diameter vector - - perimeter vector - - cell family - - section types - - topology (children/parent relationship) - - Note: the soma types are NOT required to be equal - **/ - bool operator==(const Morphology& other) const; - bool operator!=(const Morphology& other) const; - - /** @name Read API */ //@{ /** Open the given source to a morphology file and parse it. diff --git a/include/morphio/mut/morphology.h b/include/morphio/mut/morphology.h index fa6deb704..a8b5bd070 100644 --- a/include/morphio/mut/morphology.h +++ b/include/morphio/mut/morphology.h @@ -56,21 +56,6 @@ class Morphology virtual ~Morphology(); - /** - Are considered equal, 2 morphologies with the same:\n - - root sections - - section topology - - cell family - For each section: - - same points - - same diameters - - same perimeters - - same type - Note: the soma types are NOT required to be equal - **/ - bool operator==(const Morphology& other) const; - bool operator!=(const Morphology& other) const; - /** Returns all section ids at the tree root **/ diff --git a/include/morphio/mut/section.h b/include/morphio/mut/section.h index 6488b18f0..a06d47e95 100644 --- a/include/morphio/mut/section.h +++ b/include/morphio/mut/section.h @@ -96,16 +96,6 @@ class Section : public std::enable_shared_from_this
const Property::PointLevel&, SectionType sectionType = SectionType::SECTION_UNDEFINED); - /** - Two sections are equal if they have same: - - points - - diameters - - perimeters - - type - **/ - bool operator==(const Section& other) const; - bool operator!=(const Section& other) const; - private: friend class Morphology; diff --git a/include/morphio/section.h b/include/morphio/section.h index 2985f53f8..f3028543e 100644 --- a/include/morphio/section.h +++ b/include/morphio/section.h @@ -33,18 +33,6 @@ class Section : public SectionBase
using PointAttribute = Property::Point; public: - /** - Equality operator: - Are considered equal, 2 sections with the same: - - point vector - - diameter vector - - perimeter vector - - section types - - topology (children/parent relationship) - **/ - bool operator==(const Section& other) const; - bool operator!=(const Section& other) const; - /** Depth first search iterator **/ diff --git a/include/morphio/vasc/vasculature.h b/include/morphio/vasc/vasculature.h index 02f2fbd02..b7452f056 100644 --- a/include/morphio/vasc/vasculature.h +++ b/include/morphio/vasc/vasculature.h @@ -15,17 +15,6 @@ class Vasculature Vasculature(Vasculature&&); Vasculature& operator=(Vasculature&&); - /** - Equality operators : - Two vasculature morphologies are considered equal if they have the same: - - point vector - - diameter vector - - section types - - topology (successor / predecessor relationship) - **/ - bool operator==(const Vasculature& other) const; - bool operator!=(const Vasculature& other) const; - /** @name Read API */ /** Open the given source to a vasculature file and parse it. */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d57b0c8a8..db1f3b8e7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,6 @@ set(MORPHIO_SOURCES morphology.cpp soma.cpp section.cpp - tools.cpp vasc/section.cpp vasc/vasculature.cpp vasc/properties.cpp diff --git a/src/morphology.cpp b/src/morphology.cpp index 9f9f2c3cc..1086248c1 100644 --- a/src/morphology.cpp +++ b/src/morphology.cpp @@ -79,16 +79,6 @@ Morphology::~Morphology() { } -bool Morphology::operator==(const Morphology& other) const -{ - return !diff(*this, other, LogLevel::ERROR); -} - -bool Morphology::operator!=(const Morphology& other) const -{ - return diff(*this, other, LogLevel::ERROR); -} - const Soma Morphology::soma() const { return Soma(_properties); diff --git a/src/mut/morphology.cpp b/src/mut/morphology.cpp index 2a24f6a8a..a59b5f0bc 100644 --- a/src/mut/morphology.cpp +++ b/src/mut/morphology.cpp @@ -417,15 +417,5 @@ void Morphology::write(const std::string& filename) LBTHROW(UnknownFileType(_err.ERROR_WRONG_EXTENSION(filename))); } -bool Morphology::operator==(const Morphology& other) const -{ - return !diff(*this, other, LogLevel::ERROR); -} - -bool Morphology::operator!=(const Morphology& other) const -{ - return diff(*this, other, LogLevel::ERROR); -} - } // end namespace mut } // end namespace morphio diff --git a/src/mut/section.cpp b/src/mut/section.cpp index 2fcf96094..4cb765527 100644 --- a/src/mut/section.cpp +++ b/src/mut/section.cpp @@ -203,16 +203,6 @@ std::shared_ptr
Section::appendSection( return ptr; } -bool Section::operator==(const Section& other) const -{ - return !diff(*this, other, LogLevel::ERROR); -} - -bool Section::operator!=(const Section& other) const -{ - return diff(*this, other, LogLevel::ERROR); -} - } // end namespace mut } // end namespace morphio diff --git a/src/section.cpp b/src/section.cpp index 5fcd3ef4a..5b60eff3c 100644 --- a/src/section.cpp +++ b/src/section.cpp @@ -5,16 +5,6 @@ namespace morphio { -bool Section::operator==(const Section& other) const -{ - return !diff(*this, other, LogLevel::ERROR); -} - -bool Section::operator!=(const Section& other) const -{ - return diff(*this, other, LogLevel::ERROR); -} - SectionType Section::type() const { auto val = _properties->get()[_id]; diff --git a/src/tools.cpp b/src/tools.cpp deleted file mode 100644 index 6dd3d5164..000000000 --- a/src/tools.cpp +++ /dev/null @@ -1,144 +0,0 @@ -#include -#include -#include -#include -#include - - -namespace morphio -{ - -bool diff(const Morphology& left, const Morphology& right, morphio::enums::LogLevel verbose) -{ - if (left._properties->_cellLevel.diff(right._properties->_cellLevel, verbose)) - return true; - - if (left.rootSections().size() != right.rootSections().size()) { - if (verbose > LogLevel::ERROR) - std::cout << "Different number of root sections" << std::endl; - return true; - } - - for (unsigned int i = 0; i < left.rootSections().size(); ++i) - if (diff(left.rootSections()[i], right.rootSections()[i], verbose)) - return true; - - return false; -} - -bool diff(const Section& left, const Section& right, morphio::enums::LogLevel verbose) -{ - if (left.type() != right.type()) { - if (verbose > LogLevel::ERROR) - std::cout << "Reason: section type differ" << std::endl; - return true; - } - - if (left.points() != right.points()) { - if (verbose > LogLevel::ERROR) - std::cout << "Reason: points differ" << std::endl; - return true; - } - - if (left.diameters() != right.diameters()) { - if (verbose > LogLevel::ERROR) - std::cout << "Reason: diameters differ" << std::endl; - return true; - } - - if (left.perimeters() != right.perimeters()) { - if (verbose > LogLevel::ERROR) - std::cout << "Reason: perimeters differ" << std::endl; - return true; - } - - if (left.children().size() != right.children().size()) { - if (verbose > LogLevel::ERROR) - std::cout << "Reason: different number of children" << std::endl; - return true; - } - - for (unsigned int i = 0; i < left.children().size(); ++i) - if (diff(left.children()[i], right.children()[i], verbose)) { - if (verbose > LogLevel::ERROR) - { - std::cout << "Summary: children of "; - ::operator<<(std::cout, left); - std::cout << " differ. See the above \"Reason\" to know in what they differ." << std::endl; - } - - return true; - } - - return false; -} - -namespace mut -{ -bool diff(const Section& left, const Section& right, morphio::enums::LogLevel verbose) -{ - if (left.type() != right.type()) { - if (verbose > LogLevel::ERROR) - std::cout << "Reason: section type differ" << std::endl; - return true; - } - - if (left.points() != right.points()) { - if (verbose > LogLevel::ERROR) - std::cout << "Reason: points differ" << std::endl; - return true; - } - - if (left.diameters() != right.diameters()) { - if (verbose > LogLevel::ERROR) - std::cout << "Reason: diameters differ" << std::endl; - return true; - } - - if (left.perimeters() != right.perimeters()) { - if (verbose > LogLevel::ERROR) - std::cout << "Reason: perimeters differ" << std::endl; - return true; - } - - if (left.children().size() != right.children().size()) { - if (verbose > LogLevel::ERROR) - std::cout << "Reason: different number of children" << std::endl; - return true; - } - - for (unsigned int i = 0; i < left.children().size(); ++i) - if (diff(*left.children()[i], *right.children()[i], verbose)) { - if (verbose > LogLevel::ERROR) - { - std::cout << "Summary: children of "; - ::operator<<(std::cout, left); - std::cout << " differ. See the above \"Reason\" to know in what they differ." << std::endl; - } - return true; - } - - return false; -} - -bool diff(const Morphology& left, const Morphology& right, morphio::enums::LogLevel verbose) -{ - if (left._cellProperties->diff(*right._cellProperties, verbose)) - return true; - - if (left.rootSections().size() != right.rootSections().size()) { - if (verbose > LogLevel::ERROR) - std::cout << "Different number of root sections" << std::endl; - return true; - } - - for (unsigned int i = 0; i < left.rootSections().size(); ++i) - if (diff(*left.rootSections()[i], *right.rootSections()[i], verbose)) - return true; - - return false; -} - - -} // namespace mut -} // namespace morphio diff --git a/src/vasc/vasculature.cpp b/src/vasc/vasculature.cpp index 7e96c8956..62ab86315 100644 --- a/src/vasc/vasculature.cpp +++ b/src/vasc/vasculature.cpp @@ -46,18 +46,6 @@ Vasculature::~Vasculature() { } -bool Vasculature::operator==(const Vasculature& other) const -{ - if (this->_properties == other._properties) - return true; - return (this->_properties && other._properties && *(this->_properties) == *(other._properties)); -} - -bool Vasculature::operator!=(const morphio::vasculature::Vasculature& other) const -{ - return !this->operator==(other); -} - const Section Vasculature::section(const uint32_t& id) const { return Section(id, _properties); diff --git a/tests/test_1_swc.py b/tests/test_1_swc.py index 7eba4fbb2..c738071bb 100644 --- a/tests/test_1_swc.py +++ b/tests/test_1_swc.py @@ -289,30 +289,19 @@ def test_soma_type(): def test_read_weird_ids(): '''The ordering of IDs is not required''' - with tmp_swc_file('''1 1 0 0 0 3.0 -1 - 2 3 0 0 2 0.5 1 - 3 3 0 0 3 0.5 2 - 4 3 0 0 4 0.5 3 - 5 3 0 0 5 0.5 4''') as tmp_file: - - normal = Morphology(tmp_file.name) - with tmp_swc_file('''10000 3 0 0 5 0.5 100 # neurite 4th point 3 3 0 0 3 0.5 47 # neurite 2nd point 10 1 0 0 0 3.0 -1 # soma 47 3 0 0 2 0.5 10 # neurite 1st point 100 3 0 0 4 0.5 3 # neurite 3rd point ''') as tmp_file: - weird = Morphology(tmp_file.name) - - assert_equal(normal, weird) - - -def test_equality(): - filename = os.path.join(_path, 'simple.swc') - nt.ok_(not (Morphology(filename) is Morphology(filename))) - nt.ok_(Morphology(filename) == Morphology(filename)) + neuron = Morphology(tmp_file.name) + assert_array_equal(neuron.soma.points, [[0, 0, 0]]) + assert_array_equal(neuron.root_sections[0].points, [[0., 0., 2.], + [0., 0., 3.], + [0., 0., 4.], + [0., 0., 5.]]) def test_multiple_soma(): with assert_raises(SomaError) as obj: diff --git a/tests/test_2_neurolucida.py b/tests/test_2_neurolucida.py index e1e4c901b..77c8c3d81 100644 --- a/tests/test_2_neurolucida.py +++ b/tests/test_2_neurolucida.py @@ -377,17 +377,10 @@ def test_single_point_section_duplicate_parent(): ) )''') as tmp_file: - bad = Morphology(tmp_file.name) + neuron = Morphology(tmp_file.name) - with tmp_asc_file(''' - ((Dendrite) - (3 -4 0 2) - (3 -10 0 2) - )''') as tmp_file: - - good = Morphology(tmp_file.name) - - assert_equal(bad, good) + assert_array_equal(neuron.root_sections[0].points, [[ 3., -4., 0.], + [ 3., -10., 0.]]) def test_single_point_section_duplicate_parent_complex(): @@ -414,26 +407,13 @@ def test_single_point_section_duplicate_parent_complex(): ) ) ''') as bad_tmp_file: - bad = Morphology(bad_tmp_file.name) - - # Correct representation should be - with tmp_asc_file(''' -((Color Blue) - (Axon) - (1 0 0 1) - (2 0 0 1) - ( - (4 0 0 1) - | - (5 0 0 1) - | ; Bifurcation of the bifurcation - (6 0 0 1) - ) - ) -''') as good_tmp_file: - good = Morphology(good_tmp_file.name) + neuron = Morphology(bad_tmp_file.name) - ok_(good == bad) + children = neuron.root_sections[0].children + assert_equal(len(children), 3) + assert_array_equal(children[0].points, [[2, 0, 0], [4, 0, 0]]) + assert_array_equal(children[1].points, [[2, 0, 0], [5, 0, 0]]) + assert_array_equal(children[2].points, [[2, 0, 0], [6, 0, 0]]) def test_spine(): @@ -449,10 +429,6 @@ def test_spine(): [13.75, -5.96, 150.00]], dtype=np.float32)) -def test_equality_with_simple(): - ok_(Morphology(os.path.join(_path, 'simple.asc')) == - Morphology(os.path.join(_path, 'simple.swc'))) - def test_markers(): '''Test that markers do not prevent file from being read correctly''' diff --git a/tests/test_4_immut.py b/tests/test_4_immut.py index 96880b84f..b251f4b20 100644 --- a/tests/test_4_immut.py +++ b/tests/test_4_immut.py @@ -19,11 +19,6 @@ }) -def test_equality(): - for cell1, cell2 in combinations(['asc', 'swc', 'h5'], 2): - ok_(CELLS[cell1] == CELLS[cell2], '{} != {}'.format(cell1, cell2)) - - def test_is_root(): for _, cell in CELLS.items(): ok_(all(section.is_root for section in cell.root_sections)) @@ -97,15 +92,6 @@ def test_empty_vasculature(): assert_raises(RawDataError, vasculature.Vasculature, os.path.join(_path, "h5/empty_vasculature.h5")) -def test_equality_vasculature(): - morphology1 = vasculature.Vasculature(os.path.join(_path, "h5/vasculature1.h5")) - morphology1_bis = vasculature.Vasculature(os.path.join(_path, "h5/vasculature1.h5")) - morphology2 = vasculature.Vasculature(os.path.join(_path, "h5/vasculature2.h5")) - - assert_equal(morphology1, morphology1_bis) - assert_not_equal(morphology1, morphology2) - - def test_components_vasculature(): morphology = vasculature.Vasculature(os.path.join(_path, "h5/vasculature1.h5")) assert_array_almost_equal(morphology.section(0).points, diff --git a/tests/test_5_mut.py b/tests/test_5_mut.py index 8fc555a99..1eb4ce227 100644 --- a/tests/test_5_mut.py +++ b/tests/test_5_mut.py @@ -5,7 +5,7 @@ import morphio from morphio.mut import Morphology, Soma -from morphio import ostream_redirect, MitochondriaPointLevel, PointLevel, SectionType, MorphioError, SectionBuilderError, Morphology as ImmutableMorphology, upstream, depth_first, breadth_first, diff +from morphio import ostream_redirect, MitochondriaPointLevel, PointLevel, SectionType, MorphioError, SectionBuilderError, Morphology as ImmutableMorphology, upstream, depth_first, breadth_first from contextlib import contextmanager import sys from io import StringIO @@ -310,77 +310,6 @@ def test_mitochondria(): assert_array_equal(np.array(first_child.relative_path_lengths, dtype=np.float32), np.array([0.6, 0.7, 0.8, 0.9], dtype=np.float32)) -def test_equality(): - neuron_ref = Morphology(os.path.join(_path, 'simple2.asc')) - a = Morphology(os.path.join(_path, 'simple2.asc')) - assert_equal(neuron_ref, a) - ok_(not (neuron_ref != a)) - ok_(not diff(neuron_ref, a)) - - def mundane_section(neuron): - '''Not a root section, not a leaf section''' - return neuron.root_sections[0].children[0] - - def assert_expect_diff(neuron1, neuron2, expected_msg): - '''Expect diff to find a difference and return EXPECTED_MSG in stdout''' - with captured_output() as (out, _): - with ostream_redirect(stdout=True, stderr=True): - ok_(diff(neuron1, neuron2)) - assert_equal(out.getvalue().strip(), expected_msg) - - with captured_output() as (out, _): - with ostream_redirect(stdout=True, stderr=True): - ok_(diff(neuron1.as_immutable(), neuron2.as_immutable())) - assert_equal(out.getvalue().strip(), expected_msg) - - mundane_section(a).type = SectionType.apical_dendrite - assert_not_equal(neuron_ref, a) - ok_(not (neuron_ref == a)) - assert_expect_diff(neuron_ref, a, - 'Reason: section type differ\n' - 'Summary: children of Section(id=0, points=[(0 0 0),..., (0 5 0)]) differ. ' - 'See the above "Reason" to know in what they differ.') - - a = Morphology(os.path.join(_path, 'simple2.asc')) - mundane_section(a).points = [[0,0,0], [0,0,0], [0,0,1]] - assert_not_equal(neuron_ref, a) - ok_(not (neuron_ref == a)) - assert_expect_diff(neuron_ref, a, - 'Reason: points differ\n' - 'Summary: children of Section(id=0, points=[(0 0 0),..., (0 5 0)]) differ. ' - 'See the above "Reason" to know in what they differ.') - - a = Morphology(os.path.join(_path, 'simple2.asc')) - mundane_section(a).diameters = [0,0,0] - assert_not_equal(neuron_ref, a) - ok_(not (neuron_ref == a)) - assert_expect_diff(neuron_ref, a, - 'Reason: diameters differ\n' - 'Summary: children of Section(id=0, points=[(0 0 0),..., (0 5 0)]) differ. ' - 'See the above "Reason" to know in what they differ.') - - a = Morphology(os.path.join(_path, 'simple2.asc')) - for section in a.iter(): - section.perimeters = [1] * len(section.points) - assert_not_equal(neuron_ref, a) - ok_(not (neuron_ref == a)) - assert_expect_diff(neuron_ref, a, 'Reason: perimeters differ') - - a = Morphology(os.path.join(_path, 'simple2.asc')) - mundane_section(a).append_section(PointLevel([[-6, 5, 0], [4, 5, 6]], [2, 3])) - assert_not_equal(neuron_ref, a) - ok_(not (neuron_ref == a)) - assert_expect_diff(neuron_ref, a, - 'Reason: different number of children\n' - 'Summary: children of Section(id=0, points=[(0 0 0),..., (0 5 0)]) differ. ' - 'See the above "Reason" to know in what they differ.') - - a = Morphology(os.path.join(_path, 'simple2.asc')) - a.delete_section(a.root_sections[0]) - assert_not_equal(neuron_ref, a) - ok_(not (neuron_ref == a)) - assert_expect_diff(neuron_ref, a, "Different number of root sections") - def test_iterators(): assert_array_equal([sec.id for sec in SIMPLE.section(5).iter(upstream)], diff --git a/tests/test_6_writers.py b/tests/test_6_writers.py index 04a6de016..d13a87651 100644 --- a/tests/test_6_writers.py +++ b/tests/test_6_writers.py @@ -51,13 +51,12 @@ def test_write_basic(): morpho.write(os.path.join(tmp_folder, "test_write.swc")) morpho.write(os.path.join(tmp_folder, "test_write.h5")) - assert_equal(ImmutMorphology(morpho), ImmutMorphology(os.path.join(tmp_folder, "test_write.asc"))) - assert_equal(ImmutMorphology(morpho), ImmutMorphology(os.path.join(tmp_folder, "test_write.swc"))) - assert_equal(ImmutMorphology(morpho), ImmutMorphology(os.path.join(tmp_folder, "test_write.h5"))) - assert_equal(ImmutMorphology(morpho), ImmutMorphology( - os.path.join(_path, "simple.asc"))) - ok_(not (ImmutMorphology(morpho) != ImmutMorphology( - os.path.join(_path, "simple.asc")))) + expected = [[0., 0., 0.], [0., 5., 0.], [0., 5., 0.], [-5., 5., 0.], + [0., 5., 0.], [6., 5., 0.], [0., 0., 0.], [0., -4., 0.], + [0., -4., 0.], [6., -4., 0.], [0., -4., 0.], [-5., -4., 0.]] + assert_array_equal(ImmutMorphology(os.path.join(tmp_folder, "test_write.asc")).points, expected) + assert_array_equal(ImmutMorphology(os.path.join(tmp_folder, "test_write.swc")).points, expected) + assert_array_equal(ImmutMorphology(os.path.join(tmp_folder, "test_write.h5")).points, expected) def test_write_merge_only_child(): @@ -141,8 +140,8 @@ def test_write_perimeter(): with setup_tempdir('test_write_perimeter') as tmp_folder: morpho.write(os.path.join(tmp_folder, "test_write.h5")) - assert_array_equal(ImmutMorphology(morpho), - ImmutMorphology(os.path.join(tmp_folder, "test_write.h5"))) + assert_array_equal(ImmutMorphology(os.path.join(tmp_folder, "test_write.h5")).perimeters, + [5., 6., 6., 7., 6., 8.]) def test_write_no_soma(): diff --git a/tests/test_7_modifiers.py b/tests/test_7_modifiers.py index 9e47e52cc..374b9829d 100644 --- a/tests/test_7_modifiers.py +++ b/tests/test_7_modifiers.py @@ -15,7 +15,7 @@ SIMPLE_NO_MODIFIER = Morphology(SIMPLE) def test_no_modifier(): - assert_equal(SIMPLE_NO_MODIFIER, Morphology(SIMPLE, options=Option.no_modifier)) + assert_array_equal(SIMPLE_NO_MODIFIER.points, Morphology(SIMPLE, options=Option.no_modifier).points) def test_nrn_order(): m = Morphology(os.path.join(_path, 'reversed_NRN_neurite_order.swc'), options=Option.nrn_order)