Coverage for tests / test_instrument_factories.py: 80%
5 statements
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-27 14:36 +0000
« prev ^ index » next coverage.py v7.12.0, created at 2025-11-27 14:36 +0000
1import unittest
2import rivapy.instruments as instruments
3from rivapy.instruments.factory import _factory, create
6# class FactoryTestsMeta(type):
8# def __new__(cls, name, bases, attrs):
9# for k, v in _factory().items():
10# attrs["test_%s" % k] = cls.gen(v)
11# return super(FactoryTestsMeta, cls).__new__(cls, name, bases, attrs)
13# @classmethod
14# def gen(cls, target_class):
15# # Return a testcase that tests the creation of an instrument from factory
16# def fn(self):
17# try:
18# ins = target_class._create_sample(4, seed=42)
19# for i in range(len(ins)):
20# b = create(ins[i].to_dict())
21# self.assertEqual(b.hash(), ins[i].hash())
22# except AttributeError as e:
23# self.assertEqual(0, 1, msg="_create_sample not implemented for class " + target_class.__name__)
25# return fn
28# # TODO currently, the EnergyFtureSpecifications and GreenPPASpecification
29# # _create_sample() functions return List[Instrument_spec]
30# # However, from the updated Bonds Specification, upon which, deposits, fras, IR Swaps
31# # are based, these specifications return a List[Dict[instrument parameters]]
32# # and several instances of the specification are not actually initlized.
33# # this leads to the current error in the unit tests
34# # TODO: discuss desgin choice with Hans and update accordingly 2025.09.18
35# class InstrumentTests(unittest.TestCase, metaclass=FactoryTestsMeta):
36# pass
39if __name__ == "__main__":
40 unittest.main()