High-level description
This file contains unit tests for thelocal_3d
module in the Cassiopeia package. It tests various functions and classes related to 3D plotting of tree structures, including coordinate interpolation, color manipulation, label generation, and the main Tree3D
class.
Code Structure
The main test classTestLocal3DPlotting
inherits from unittest.TestCase
. It sets up a simulated tree and spatial data in the setUp
method, which is then used across multiple test methods. Each test method focuses on a specific function or aspect of the local_3d
module.
Symbols
TestLocal3DPlotting
Description
A test class that contains multiple unit tests for thelocal_3d
module.
Internal Logic
- Sets up a simulated tree and spatial data in
setUp
. - Tests individual functions like
interpolate_branch
,polyline_from_points
,average_mixing
, etc. - Tests the
labels_from_coordinates
function with various inputs and edge cases. - Tests the initialization of the
Tree3D
class.
test_interpolate_branch
Description
Tests theinterpolate_branch
function from the local_3d
module.
Internal Logic
Checks if the function correctly interpolates a branch between two 3D points.test_polyline_from_points
Description
Tests thepolyline_from_points
function from the local_3d
module.
Internal Logic
Verifies if the function correctly creates a polyline from a set of 3D points.test_average_mixing
Description
Tests theaverage_mixing
function from the local_3d
module.
Internal Logic
Checks if the function correctly averages multiple colors.test_highlight
Description
Tests thehighlight
function from the local_3d
module.
Internal Logic
Verifies if the function correctly brightens a given color.test_lowlight
Description
Tests thelowlight
function from the local_3d
module.
Internal Logic
Checks if the function correctly dims a given color.test_labels_from_coordinates
Description
Tests thelabels_from_coordinates
function from the local_3d
module.
Internal Logic
- Tests various invalid inputs (shape, attribute key).
- Checks if the function correctly generates labels and updates tree metadata.
- Tests with non-square shapes and dense spatial positions.
test_Tree3D
Description
Tests the initialization of theTree3D
class from the local_3d
module.
Internal Logic
InitializesTree3D
objects with and without labels and calls the plot
method to ensure no errors occur.
Dependencies
The test file depends on the following modules:Dependency | Purpose |
---|---|
unittest | Provides the testing framework |
unittest.mock | Used for mocking objects in tests |
networkx | Graph library (imported but not used in the provided code) |
numpy | Used for numerical operations and assertions |
pandas | Data manipulation library (imported but not used in the provided code) |
cassiopeia | The main package being tested |
Error Handling
The test methods use variousassert
statements and self.assertRaises
to check for expected behaviors and error conditions.