mirror of
https://github.com/Telecominfraproject/oopt-gnpy.git
synced 2025-10-31 18:18:00 +00:00
The code look as if it was trying to prevent direct instantiation of the SimParams class. However, instance *creation* in Python is actually handled via `__new__` which was not overridden. In addition, the `get()` accessor was invoking `SimParams.__new__()` directly, which meant that this class was instantiated each time it was needed. Let's cut the boilerplate by getting rid of the extra step and just use the regular constructor. This patch doesn't change anything in actual observable behavior. I still do not like this implicit singleton design pattern, but nuking that will have to wait until some other time. Change-Id: I3ca81bcd0042e91b4f6b7581879922611f18febe
24 lines
623 B
Python
24 lines
623 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
Checks that the class SimParams behaves as a mutable Singleton.
|
|
"""
|
|
|
|
import pytest
|
|
from gnpy.core.parameters import SimParams
|
|
|
|
|
|
@pytest.mark.usefixtures('set_sim_params')
|
|
def test_sim_parameters():
|
|
sim_params = {'nli_params': {}, 'raman_params': {}}
|
|
SimParams.set_params(sim_params)
|
|
s1 = SimParams()
|
|
assert s1.nli_params.method == 'gn_model_analytic'
|
|
s2 = SimParams()
|
|
assert not s1.raman_params.flag
|
|
sim_params['raman_params']['flag'] = True
|
|
SimParams.set_params(sim_params)
|
|
assert s2.raman_params.flag
|
|
assert s1.raman_params.flag
|