<commit_before>import gdsfactory as gf
from gdsfactory.import_gds import import_gds


def test_import_gds_snap_to_grid() -> None:
    gdspath = gf.CONFIG["gdsdir"] / "mmi1x2.gds"
    c = import_gds(gdspath, snap_to_grid_nm=5)
    assert len(c.get_polygons()) == 8, len(c.get_polygons())

    for x, y in c.get_polygons()[0]:
        assert gf.snap.is_on_grid(x, 5)
        assert gf.snap.is_on_grid(y, 5)


def test_import_gds_hierarchy() -> None:
    c0 = gf.components.mzi()
    gdspath = c0.write_gds()
    c = import_gds(gdspath)
    assert len(c.get_dependencies()) == 3, len(c.get_dependencies())


if __name__ == "__main__":
    # test_import_gds_hierarchy()
    test_import_gds_snap_to_grid()<commit_msg>add more tests for import_gds<commit_after>import gdsfactory as gf
from gdsfactory.import_gds import add_ports_from_markers_inside, import_gds


def test_import_gds_snap_to_grid() -> None:
    gdspath = gf.CONFIG["gdsdir"] / "mmi1x2.gds"
    c = import_gds(gdspath, snap_to_grid_nm=5)
    assert len(c.get_polygons()) == 8, len(c.get_polygons())

    for x, y in c.get_polygons()[0]:
        assert gf.snap.is_on_grid(x, 5)
        assert gf.snap.is_on_grid(y, 5)


def test_import_gds_hierarchy() -> gf.Component:
    c0 = gf.components.mzi()
    gdspath = c0.write_gds()
    gf.clear_cache()

    c = import_gds(gdspath)
    assert len(c.get_dependencies()) == 3, len(c.get_dependencies())
    assert c.name == "mzi", c.name
    return c


def test_import_ports() -> gf.Component:
    """Make sure you can import the ports"""
    c0 = gf.components.mzi(decorator=gf.add_pins)
    gdspath = c0.write_gds()
    c0x1 = c0.ports["o1"].x
    c0x2 = c0.ports["o2"].x
    gf.clear_cache()

    c1 = import_gds(gdspath, decorator=add_ports_from_markers_inside)
    c1x1 = c1.ports["o1"].x
    c1x2 = c1.ports["o2"].x

    assert c0x1 == c1x1
    assert c0x2 == c1x2
    return c1


def test_import_gds_add_padding() -> gf.Component:
    """Make sure you can import the ports"""
    c0 = gf.components.mzi(decorator=gf.add_pins)
    gdspath = c0.write_gds()
    gf.clear_cache()

    c1 = import_gds(gdspath, decorator=gf.add_padding_container, name="mzi")
    c1.name == "mzi"
    return c1


if __name__ == "__main__":
    # c = test_import_gds_hierarchy()
    # c = test_import_ports()
    c = test_import_gds_add_padding()
    c.show()
    # test_import_gds_snap_to_grid()
{'fraction_non_alphanumeric': 0.13271734565308693, 'fraction_numerical': 0.022259554808903823, 'mean_word_length': 3.5984555984555984, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7641174', 'n_tokens_mistral': 1029, 'n_tokens_neox': 988, 'n_words': 174}