Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ports tests #595

Merged
merged 17 commits into from
Jan 31, 2025
Merged

Add ports tests #595

merged 17 commits into from
Jan 31, 2025

Conversation

MatthewMckee4
Copy link
Member

@MatthewMckee4 MatthewMckee4 commented Jan 30, 2025

Summary by Sourcery

Add support for Ports in kfactory.

New Features:

  • Add Ports.filter, Ports.contains, Ports.create_port, Ports.get_all_named, Ports.copy, Ports.print, and Ports.pformat methods.
  • Add support for DPorts.
  • Add support for InstancePorts.
  • Add support for creating ports from YAML files.

Tests:

  • Add tests for ports, dports, and instance ports.

Copy link
Contributor

sourcery-ai bot commented Jan 30, 2025

Reviewer's Guide by Sourcery

This pull request introduces comprehensive tests for the Ports and DPorts classes, enhancing the robustness of port handling within the kfactory library. It includes tests for filtering, equality checks, port creation, copying, and more. Additionally, it refactors the settings classes to use a mixin for shared functionality and adds a repr method to several classes.

Class diagram for Settings refactoring

classDiagram
    class SettingMixin {
      +__getitem__(key: str)
      +get(__key: str, default: Any)
      +__contains__(__key: str)
      +__str__()
    }
    class KCellSettings {
      +restrict_types(data: dict)
    }
    class KCellSettingsUnits {
      +restrict_types(data: dict)
    }
    class Info {
      +restrict_types(data: dict)
      +update(data: dict)
      +__setitem__(key: str, value: MetaData)
      +__iadd__(other: Info)
      +__add__(other: Info)
    }

    SettingMixin <|-- KCellSettings
    SettingMixin <|-- KCellSettingsUnits
    SettingMixin <|-- Info

    note for SettingMixin "New mixin class for shared settings functionality"
    note for KCellSettings "Settings for BaseKCell"
    note for KCellSettingsUnits "Settings for KCell units"
    note for Info "Info for KCell"
Loading

Class diagram for Ports and DPorts

classDiagram
    class ProtoPort {
      <<abstract>>
      +name: str
      +port_type: str
      +layer: LayerEnum
      +width: float|int
    }
    class Port {
      +width: int
      +__repr__()
    }
    class DPort {
      +width: float
      +__repr__()
    }
    class ProtoPorts {
      <<abstract>>
      +create_port()
      +__eq__(other)
      +clear()
    }
    class Ports {
      +create_port(width: int, layer, ...)
    }
    class DPorts {
      +create_port(width: float, layer, ...)
    }

    ProtoPort <|-- Port
    ProtoPort <|-- DPort
    ProtoPorts <|-- Ports
    ProtoPorts <|-- DPorts
    Ports o-- Port
    DPorts o-- DPort

    note for Port "Integer-based port (DBU)"
    note for DPort "Float-based port (microns)"
Loading

File-Level Changes

Change Details Files
Added comprehensive tests for Ports and DPorts classes.
  • Added tests for filtering ports by angle, orientation, layer, regex, and port type.
  • Added tests to check if a port is contained within a Ports object.
  • Added tests for equality comparisons between Ports objects.
  • Added tests for creating new ports with various parameters and error handling.
  • Added tests for retrieving all named ports.
  • Added tests for copying Ports objects, including renaming ports during copy.
  • Added tests for printing and formatting Ports objects.
  • Added tests for accessing ports using indexing and key lookups.
  • Added tests for adding ports to DPorts objects.
  • Added tests for creating ports in DPorts objects with various parameters and error handling.
  • Added tests for retrieving all named ports in DPorts objects.
  • Added tests for accessing ports using indexing and key lookups in DPorts objects.
  • Added tests for copying DPorts objects, including renaming ports during copy.
  • Added tests for filtering DPorts objects.
  • Added tests for printing and formatting DPorts objects.
tests/test_ports.py
Refactored settings classes to use a mixin for shared functionality.
  • Introduced a SettingMixin class to encapsulate shared methods.
  • Modified KCellSettings, KCellSettingsUnits, and Info classes to inherit from SettingMixin.
  • Added a str method to the SettingMixin class.
  • Removed redundant methods from KCellSettings, KCellSettingsUnits, and Info classes.
src/kfactory/settings.py
Added a repr method to several classes.
  • Added a repr method to the KCell class.
  • Added a repr method to the TKCell class.
  • Added a repr method to the ProtoInstances class.
  • Added a repr method to the ProtoInstancePorts class.
  • Added a repr method to the KCLayout class.
src/kfactory/kcell.py
src/kfactory/instances.py
src/kfactory/layout.py
src/kfactory/instance_ports.py
Added a test for cell yaml serialization.
  • Added a test to verify that cells can be serialized and deserialized using YAML.
tests/test_cell.py
Added a test for layer stack.
  • Added a test to verify that layer stacks can be accessed.
tests/test_layers.py
Added a contains method to instance ports.
  • Added a contains method to the ProtoInstancePorts class.
src/kfactory/instance_ports.py
Removed mirror property from ports.
  • Removed the mirror property from the Port and DPort classes.
src/kfactory/port.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added the enhancement New feature or request label Jan 30, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.

src/kfactory/instance_ports.py Outdated Show resolved Hide resolved
src/kfactory/ports.py Outdated Show resolved Hide resolved
tests/test_ports.py Outdated Show resolved Hide resolved
MatthewMckee4 and others added 5 commits January 30, 2025 22:51
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

Attention: Patch coverage is 91.89189% with 12 lines in your changes missing coverage. Please review.

Project coverage is 66.00%. Comparing base (966e95d) to head (674dd08).
Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
src/kfactory/instances.py 50.00% 2 Missing and 1 partial ⚠️
src/kfactory/port.py 96.47% 0 Missing and 3 partials ⚠️
src/kfactory/cross_section.py 80.00% 1 Missing and 1 partial ⚠️
src/kfactory/instance_ports.py 66.66% 1 Missing and 1 partial ⚠️
src/kfactory/kcell.py 80.00% 1 Missing ⚠️
src/kfactory/settings.py 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #595      +/-   ##
==========================================
+ Coverage   63.61%   66.00%   +2.39%     
==========================================
  Files          64       64              
  Lines        9561     9504      -57     
  Branches     1777     1771       -6     
==========================================
+ Hits         6082     6273     +191     
+ Misses       2928     2714     -214     
+ Partials      551      517      -34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MatthewMckee4 MatthewMckee4 merged commit 7f2f976 into main Jan 31, 2025
16 checks passed
@MatthewMckee4 MatthewMckee4 deleted the ports-tests branch January 31, 2025 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants