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.