utilities_test.py
Here’s a comprehensive documentation for the provided test file:
High-level description
This file contains unit tests for the utility functions used in plotting trees and other visualizations in the Cassiopeia project. It tests various functions from the cassiopeia.plotting.utilities
module, ensuring their correctness and expected behavior.
Code Structure
The main class TestPlottingUtilities
inherits from unittest.TestCase
and contains multiple test methods, each focusing on a specific utility function or feature. The setUp
method initializes common test data used across multiple test cases.
Symbols
TestPlottingUtilities
Description
A test class that contains unit tests for various plotting utility functions in the Cassiopeia project.
Internal Logic
- Sets up test data in the
setUp
method. - Implements multiple test methods, each targeting a specific utility function.
setUp
Description
Initializes test data used across multiple test cases.
Internal Logic
- Sets a random state for reproducibility.
- Creates a sample indel priors DataFrame.
- Constructs a basic tree structure using NetworkX.
- Sets attributes on the tree nodes.
test_degrees_to_radians
Description
Tests the degrees_to_radians
function for correct conversion.
Internal Logic
Asserts that 180 degrees equals π radians and 90 degrees equals π/2 radians.
test_polar_to_cartesian
Description
Tests the polar_to_cartesian
function for correct conversion.
Internal Logic
Checks conversion for 0 and 90 degrees with a radius of 1.
test_generate_random_color
Description
Tests the generate_random_color
function for generating random colors within specified ranges.
Internal Logic
- Defines color intervals.
- Generates a random color using the function.
- Asserts that the generated color components are within expected ranges.
test_place_tree
Description
Tests the place_tree
function for correct placement of tree nodes and branches.
Internal Logic
- Tests tree placement with default settings.
- Tests tree placement without extending branches.
- Tests tree placement using a custom depth key.
- Tests tree placement with branch extension and custom depth key.
- Tests tree placement in polar coordinates.
test_place_colorstrip
Description
Tests the place_colorstrip
function for correct placement of color strips.
Internal Logic
Tests color strip placement in different directions (right, left, up, down) and checks the resulting coordinates.
test_generate_indel_colors_from_priors
Description
Tests the get_indel_colors
function for generating colors based on indel priors.
Internal Logic
- Generates indel colors using the function.
- Compares the generated colors with expected values.
test_color_converters
Description
Tests the hex to RGB and RGB to hex color conversion functions.
Internal Logic
- Tests conversion from hex to RGB.
- Tests conversion from RGB to hex.
test_generate_random_indel_colors
Description
Tests the get_random_indel_colors
function for generating random colors for indels.
Internal Logic
- Creates a sample lineage profile.
- Generates random indel colors using the function.
- Compares the generated colors with expected values.
Dependencies
- unittest
- networkx
- numpy
- pandas
- cassiopeia
Error Handling
The test cases use various assertion methods from the unittest
module to check for expected outcomes and raise errors if the results don’t match the expectations.
Your response should not exceed 3000 words or 4000 tokens. Focus on providing clear, concise information that can be directly inferred from the code. Include optional sections only when they provide significant value for understanding the code.