Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
slayoo committed Aug 1, 2024
1 parent cf75393 commit bd3a273
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tests/unit_tests/products/test_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
TotalDryMassMixingRatio,
VolumeStandardDeviation,
)
from PySDM.products.impl.product import Product
from PySDM.products.impl.rate_product import RateProduct
from PySDM.products.impl import Product, RateProduct, register_product

_ARGUMENTS = {
AqueousMassSpectrum: {"key": "S_VI", "dry_radius_bins_edges": (0, np.inf)},
Expand Down Expand Up @@ -155,3 +154,32 @@ def test_register_can_be_called_twice_on_r_eff():

# act
sut.register(builder)

@staticmethod
def test_register_product_make_product_instances_reusable():
# arrange
name = "prod"

@register_product()
class Prod(Product):
def __init__(self, unit="m"):
super().__init__(unit=unit, name=name)

def _impl(self, **_):
pass

product = Prod()
kwargs = {"backend": CPU(), "n_sd": 0, "environment": Box(dt=0, dv=0)}
builders = (
Builder(**kwargs),
Builder(**kwargs),
)

# act
for builder in builders:
builder._register_product(product=product, buffer=None)

# assert
assert product.particulator is None
for builder in builders:
assert builder.particulator.products[name] is not product

0 comments on commit bd3a273

Please sign in to comment.