Skip to content
Snippets Groups Projects

Doc-tests

Merged Martin Lange requested to merge doc-tests into main
3 files
+ 47
22
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -31,7 +31,7 @@ which is called from downstream to request data.
File ``src/scale.py``:
.. code-block:: Python
.. testcode:: scale-adapter
import finam as fm
@@ -45,6 +45,11 @@ File ``src/scale.py``:
d = self.pull_data(time)
return d * self.scale
.. testcode:: scale-adapter
:hide:
adapter = Scale(0.5)
In :meth:`.Adapter._get_data`, we:
1. Pull the input for the requested ``time``
@@ -129,6 +134,10 @@ In :meth:`.Adapter._source_updated`, we need to store incoming data:
self.old_data = None
self.new_data = None
@property
def needs_push(self):
return True
def _source_updated(self, time):
self.old_data = self.new_data
self.new_data = (time, fm.data.strip_data(self.pull_data(time)))
@@ -141,7 +150,7 @@ As the output time will differ from the input time, we need to strip the time of
In :meth:`.Adapter._get_data`, we can now do the interpolation whenever data is requested from upstream.
.. code-block:: Python
.. testcode:: time-adapter
import finam as fm
@@ -152,6 +161,10 @@ In :meth:`.Adapter._get_data`, we can now do the interpolation whenever data is
self.old_data = None
self.new_data = None
@property
def needs_push(self):
return True
def _source_updated(self, time):
self.old_data = self.new_data
self.new_data = (time, fm.data.strip_data(self.pull_data(time)))
@@ -167,6 +180,11 @@ In :meth:`.Adapter._get_data`, we can now do the interpolation whenever data is
return o + dt * (n - o)
.. testcode:: time-adapter
:hide:
adapter = TimeInterpolation()
In :meth:`.Adapter._get_data`, the following happens:
1. If only one data entry was received so far, we can't interpolate and simply return the available data. Otherwise...
Loading