> ## Documentation Index
> Fetch the complete documentation index at: https://demo.agenticlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 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

1. Sets up test data in the `setUp` method.
2. Implements multiple test methods, each targeting a specific utility function.

### setUp

#### Description

Initializes test data used across multiple test cases.

#### Internal Logic

1. Sets a random state for reproducibility.
2. Creates a sample indel priors DataFrame.
3. Constructs a basic tree structure using NetworkX.
4. 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

1. Defines color intervals.
2. Generates a random color using the function.
3. 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

1. Tests tree placement with default settings.
2. Tests tree placement without extending branches.
3. Tests tree placement using a custom depth key.
4. Tests tree placement with branch extension and custom depth key.
5. 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

1. Generates indel colors using the function.
2. 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

1. Tests conversion from hex to RGB.
2. 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

1. Creates a sample lineage profile.
2. Generates random indel colors using the function.
3. 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.
