<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import unittest

from hwt.interfaces.std import VldSynced
from hwt.serializer.vhdl.serializer import VhdlSerializer
from hwt.synthesizer.param import Param
from hwt.synthesizer.unit import Unit
from hwt.synthesizer.utils import toRtl
from hwt.interfaces.utils import addClkRstn
from hwt.synthesizer.hObjList import HObjList
from hwtLib.amba.axis import AxiStream
from hwtLib.examples.hierarchy.unitWrapper import UnitWrapper
import os


class ArrayIntfExample(Unit):
    """
    .. hwt-schematic::
    """

    def _declr(self):
        addClkRstn(self)
        self.a = HObjList(AxiStream() for _ in range(2))

    def _impl(self):
        for intf in self.a:
            intf.ready(1)


class UnitWithParams(Unit):
    """
    .. hwt-schematic::
    """
    def _config(self):
        self.DATA_WIDTH = Param(64)

    def _declr(self):
        self.din = VldSynced()
        self.dout = VldSynced()._m()

    def _impl(self):
        self.dout(self.din)


def readContent(fn):
    with open(os.path.join(os.path.dirname(__file__), fn)) as f:
        return f.read()


class UnitWrapperTC(unittest.TestCase):
    def test_params_of_base_unit(self):
        u = UnitWithParams()
        w = UnitWrapper(u)
        s = toRtl(w, serializer=VhdlSerializer)
        UnitWithParams_in_wrap_vhdl = readContent("UnitWithParams_in_wrap.vhd")
        self.assertEqual(s, UnitWithParams_in_wrap_vhdl)

    def test_interfaces(self):
        u = UnitWrapper(ArrayIntfExample())
        toRtl(u)
        self.assertTrue(hasattr(u, "a_0"))
        self.assertTrue(hasattr(u, "a_1"))
        self.assertFalse(hasattr(u, "a"))


if __name__ == "__main__":
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(UnitWrapperTC))<commit_msg>use new simulator API in examples.hierarchy<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from hwt.interfaces.std import VldSynced
from hwt.interfaces.utils import addClkRstn
from hwt.serializer.vhdl.serializer import VhdlSerializer
from hwt.synthesizer.hObjList import HObjList
from hwt.synthesizer.param import Param
from hwt.synthesizer.unit import Unit
from hwt.synthesizer.utils import toRtl
import os
import unittest
from unittest import TestCase

from hwtLib.amba.axis import AxiStream
from hwtLib.examples.hierarchy.unitWrapper import UnitWrapper


class ArrayIntfExample(Unit):
    """
    .. hwt-schematic::
    """

    def _declr(self):
        addClkRstn(self)
        self.a = HObjList(AxiStream() for _ in range(2))

    def _impl(self):
        for intf in self.a:
            intf.ready(1)


class UnitWithParams(Unit):
    """
    .. hwt-schematic::
    """
    def _config(self):
        self.DATA_WIDTH = Param(64)

    def _declr(self):
        self.din = VldSynced()
        self.dout = VldSynced()._m()

    def _impl(self):
        self.dout(self.din)


def readContent(fn):
    with open(os.path.join(os.path.dirname(__file__), fn)) as f:
        return f.read()


class UnitWrapperTC(TestCase):
    def test_params_of_base_unit(self):
        u = UnitWithParams()
        w = UnitWrapper(u)
        s = toRtl(w, serializer=VhdlSerializer)
        UnitWithParams_in_wrap_vhdl = readContent("UnitWithParams_in_wrap.vhd")
        self.assertEqual(s, UnitWithParams_in_wrap_vhdl)

    def test_interfaces(self):
        u = UnitWrapper(ArrayIntfExample())
        toRtl(u)
        self.assertTrue(hasattr(u, "a_0"))
        self.assertTrue(hasattr(u, "a_1"))
        self.assertFalse(hasattr(u, "a"))


if __name__ == "__main__":
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(UnitWrapperTC))
{'fraction_non_alphanumeric': 0.11442649876813578, 'fraction_numerical': 0.0043799616753353405, 'mean_word_length': 3.171232876712329, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '1450929', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1263, 'n_words': 246}