From 62e8c800f4644557bcd3bbf4d46ce8b27a5de0b6 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Sat, 3 Nov 2018 22:36:37 -0700 Subject: [PATCH 1/5] Fix passing tuples/lists into RendererLayout --- ovgenpy/renderer.py | 6 ++++-- tests/test_renderer.py | 29 ++++++++++++++--------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/ovgenpy/renderer.py b/ovgenpy/renderer.py index 439b86e..b6ee2c8 100644 --- a/ovgenpy/renderer.py +++ b/ovgenpy/renderer.py @@ -248,8 +248,10 @@ class RendererLayout: inds = np.arange(nspaces) rows, cols = np.unravel_index(inds, (self.nrows, self.ncols)) - row_col = np.array([rows, cols]).T - regions = np.array([region_factory(*rc) for rc in row_col]) # type: np.ndarray[Region] + row_col = list(zip(rows, cols)) + regions = np.empty(len(row_col), dtype=object) # type: np.ndarray[Region] + regions[:] = [region_factory(*rc) for rc in row_col] + regions2d = regions.reshape((self.nrows, self.ncols)) # type: np.ndarray[Region] # if column major: diff --git a/tests/test_renderer.py b/tests/test_renderer.py index ac10132..9d22f8d 100644 --- a/tests/test_renderer.py +++ b/tests/test_renderer.py @@ -31,44 +31,43 @@ def test_config(): LayoutConfig(ncols=2), LayoutConfig(nrows=8), ]) -def test_hlayout(lcfg): +@pytest.mark.parametrize('region_type', [str, tuple, list]) +def test_hlayout(lcfg, region_type): nplots = 15 layout = RendererLayout(lcfg, nplots) assert layout.ncols == 2 assert layout.nrows == 8 - # holy shit, passing tuples into a numpy array breaks things spectacularly, and it's - # painfully difficult to stuff tuples into 1D array. - # http://wesmckinney.com/blog/performance-quirk-making-a-1d-object-ndarray-of-tuples/ - regions = layout.arrange(lambda row, col: str((row, col))) + regions = layout.arrange(lambda row, col: region_type((row, col))) assert len(regions) == nplots - assert regions[0] == '(0, 0)' - assert regions[1] == '(0, 1)' - assert regions[2] == '(1, 0)' + assert regions[0] == region_type((0, 0)) + assert regions[1] == region_type((0, 1)) + assert regions[2] == region_type((1, 0)) m = nplots - 1 - assert regions[m] == str((m // 2, m % 2)) + assert regions[m] == region_type((m // 2, m % 2)) @pytest.mark.parametrize('lcfg', [ LayoutConfig(ncols=3, orientation='v'), LayoutConfig(nrows=3, orientation='v'), ]) -def test_vlayout(lcfg): +@pytest.mark.parametrize('region_type', [str, tuple, list]) +def test_vlayout(lcfg, region_type): nplots = 7 layout = RendererLayout(lcfg, nplots) assert layout.ncols == 3 assert layout.nrows == 3 - regions = layout.arrange(lambda row, col: str((row, col))) + regions = layout.arrange(lambda row, col: region_type((row, col))) assert len(regions) == nplots - assert regions[0] == '(0, 0)' - assert regions[2] == '(2, 0)' - assert regions[3] == '(0, 1)' - assert regions[6] == '(0, 2)' + assert regions[0] == region_type((0, 0)) + assert regions[2] == region_type((2, 0)) + assert regions[3] == region_type((0, 1)) + assert regions[6] == region_type((0, 2)) def test_renderer(): From 342752febfb2d8afd138f88e862ffd52c9628289 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Sat, 3 Nov 2018 22:53:07 -0700 Subject: [PATCH 2/5] Move LayoutConfig and RendererLayout to new file --- ovgenpy/layout.py | 87 ++++++++++++++++++++++++++++++++++++++++++ ovgenpy/ovgenpy.py | 3 +- ovgenpy/renderer.py | 84 ++-------------------------------------- tests/test_layout.py | 77 +++++++++++++++++++++++++++++++++++++ tests/test_renderer.py | 85 +---------------------------------------- 5 files changed, 171 insertions(+), 165 deletions(-) create mode 100644 ovgenpy/layout.py create mode 100644 tests/test_layout.py diff --git a/ovgenpy/layout.py b/ovgenpy/layout.py new file mode 100644 index 0000000..b487daf --- /dev/null +++ b/ovgenpy/layout.py @@ -0,0 +1,87 @@ +from typing import Optional, TypeVar, Callable, List + +import numpy as np + +from ovgenpy.config import register_config +from ovgenpy.util import ceildiv + + +@register_config(always_dump='orientation') +class LayoutConfig: + orientation: str = 'h' + nrows: Optional[int] = None + ncols: Optional[int] = None + + def __post_init__(self): + if not self.nrows: + self.nrows = None + if not self.ncols: + self.ncols = None + + if self.nrows and self.ncols: + raise ValueError('cannot manually assign both nrows and ncols') + + if not self.nrows and not self.ncols: + self.ncols = 1 + + +Region = TypeVar('Region') +RegionFactory = Callable[[int, int], Region] # f(row, column) -> Region + + +class RendererLayout: + VALID_ORIENTATIONS = ['h', 'v'] + + def __init__(self, cfg: LayoutConfig, nplots: int): + self.cfg = cfg + self.nplots = nplots + + # Setup layout + self.nrows, self.ncols = self._calc_layout() + + self.orientation = cfg.orientation + if self.orientation not in self.VALID_ORIENTATIONS: + raise ValueError(f'Invalid orientation {self.orientation} not in ' + f'{self.VALID_ORIENTATIONS}') + + def _calc_layout(self): + """ + Inputs: self.cfg, self.waves + :return: (nrows, ncols) + """ + cfg = self.cfg + + if cfg.nrows: + nrows = cfg.nrows + if nrows is None: + raise ValueError('invalid cfg: rows_first is True and nrows is None') + ncols = ceildiv(self.nplots, nrows) + else: + ncols = cfg.ncols + if ncols is None: + raise ValueError('invalid cfg: rows_first is False and ncols is None') + nrows = ceildiv(self.nplots, ncols) + + return nrows, ncols + + def arrange(self, region_factory: RegionFactory) -> List[Region]: + """ Generates an array of regions. + + index, row, column are fed into region_factory in a row-major order [row][col]. + The results are possibly reshaped into column-major order [col][row]. + """ + nspaces = self.nrows * self.ncols + inds = np.arange(nspaces) + rows, cols = np.unravel_index(inds, (self.nrows, self.ncols)) + + row_col = list(zip(rows, cols)) + regions = np.empty(len(row_col), dtype=object) # type: np.ndarray[Region] + regions[:] = [region_factory(*rc) for rc in row_col] + + regions2d = regions.reshape((self.nrows, self.ncols)) # type: np.ndarray[Region] + + # if column major: + if self.orientation == 'v': + regions2d = regions2d.T + + return regions2d.flatten()[:self.nplots].tolist() diff --git a/ovgenpy/ovgenpy.py b/ovgenpy/ovgenpy.py index 3e1a746..d0ccb93 100644 --- a/ovgenpy/ovgenpy.py +++ b/ovgenpy/ovgenpy.py @@ -8,7 +8,8 @@ from typing import Optional, List, Union, TYPE_CHECKING from ovgenpy import outputs from ovgenpy.channel import Channel, ChannelConfig from ovgenpy.config import register_config, register_enum, Ignored -from ovgenpy.renderer import MatplotlibRenderer, RendererConfig, LayoutConfig +from ovgenpy.renderer import MatplotlibRenderer, RendererConfig +from ovgenpy.layout import LayoutConfig from ovgenpy.triggers import ITriggerConfig, CorrelationTriggerConfig, PerFrameCache, \ LocalPostTriggerConfig from ovgenpy.util import pushd, coalesce diff --git a/ovgenpy/renderer.py b/ovgenpy/renderer.py index b6ee2c8..7da88bb 100644 --- a/ovgenpy/renderer.py +++ b/ovgenpy/renderer.py @@ -1,11 +1,12 @@ -from typing import Optional, List, TYPE_CHECKING, TypeVar, Callable, Any +from typing import Optional, List, TYPE_CHECKING, Any import matplotlib import numpy as np from ovgenpy.config import register_config +from ovgenpy.layout import RendererLayout from ovgenpy.outputs import RGB_DEPTH -from ovgenpy.util import ceildiv, coalesce +from ovgenpy.util import coalesce matplotlib.use('agg') from matplotlib import pyplot as plt @@ -180,82 +181,3 @@ class MatplotlibRenderer: return buffer_rgb -@register_config(always_dump='orientation') -class LayoutConfig: - orientation: str = 'h' - nrows: Optional[int] = None - ncols: Optional[int] = None - - def __post_init__(self): - if not self.nrows: - self.nrows = None - if not self.ncols: - self.ncols = None - - if self.nrows and self.ncols: - raise ValueError('cannot manually assign both nrows and ncols') - - if not self.nrows and not self.ncols: - self.ncols = 1 - - -Region = TypeVar('Region') -RegionFactory = Callable[[int, int], Region] # f(row, column) -> Region - - -class RendererLayout: - VALID_ORIENTATIONS = ['h', 'v'] - - def __init__(self, cfg: LayoutConfig, nplots: int): - self.cfg = cfg - self.nplots = nplots - - # Setup layout - self.nrows, self.ncols = self._calc_layout() - - self.orientation = cfg.orientation - if self.orientation not in self.VALID_ORIENTATIONS: - raise ValueError(f'Invalid orientation {self.orientation} not in ' - f'{self.VALID_ORIENTATIONS}') - - def _calc_layout(self): - """ - Inputs: self.cfg, self.waves - :return: (nrows, ncols) - """ - cfg = self.cfg - - if cfg.nrows: - nrows = cfg.nrows - if nrows is None: - raise ValueError('invalid cfg: rows_first is True and nrows is None') - ncols = ceildiv(self.nplots, nrows) - else: - ncols = cfg.ncols - if ncols is None: - raise ValueError('invalid cfg: rows_first is False and ncols is None') - nrows = ceildiv(self.nplots, ncols) - - return nrows, ncols - - def arrange(self, region_factory: RegionFactory) -> List[Region]: - """ Generates an array of regions. - - index, row, column are fed into region_factory in a row-major order [row][col]. - The results are possibly reshaped into column-major order [col][row]. - """ - nspaces = self.nrows * self.ncols - inds = np.arange(nspaces) - rows, cols = np.unravel_index(inds, (self.nrows, self.ncols)) - - row_col = list(zip(rows, cols)) - regions = np.empty(len(row_col), dtype=object) # type: np.ndarray[Region] - regions[:] = [region_factory(*rc) for rc in row_col] - - regions2d = regions.reshape((self.nrows, self.ncols)) # type: np.ndarray[Region] - - # if column major: - if self.orientation == 'v': - regions2d = regions2d.T - - return regions2d.flatten()[:self.nplots].tolist() diff --git a/tests/test_layout.py b/tests/test_layout.py new file mode 100644 index 0000000..949a3c9 --- /dev/null +++ b/tests/test_layout.py @@ -0,0 +1,77 @@ +import pytest + +from ovgenpy.layout import LayoutConfig, RendererLayout +from ovgenpy.renderer import RendererConfig, MatplotlibRenderer +from tests.test_renderer import WIDTH, HEIGHT + + +def test_layout_config(): + with pytest.raises(ValueError): + LayoutConfig(nrows=1, ncols=1) + + one_col = LayoutConfig(ncols=1) + assert one_col + + one_row = LayoutConfig(nrows=1) + assert one_row + + default = LayoutConfig() + assert default.ncols == 1 # Should default to single-column layout + assert default.nrows is None + assert default.orientation == 'h' + + +@pytest.mark.parametrize('lcfg', [ + LayoutConfig(ncols=2), + LayoutConfig(nrows=8), +]) +@pytest.mark.parametrize('region_type', [str, tuple, list]) +def test_hlayout(lcfg, region_type): + nplots = 15 + layout = RendererLayout(lcfg, nplots) + + assert layout.ncols == 2 + assert layout.nrows == 8 + + regions = layout.arrange(lambda row, col: region_type((row, col))) + assert len(regions) == nplots + + assert regions[0] == region_type((0, 0)) + assert regions[1] == region_type((0, 1)) + assert regions[2] == region_type((1, 0)) + m = nplots - 1 + assert regions[m] == region_type((m // 2, m % 2)) + + +@pytest.mark.parametrize('lcfg', [ + LayoutConfig(ncols=3, orientation='v'), + LayoutConfig(nrows=3, orientation='v'), +]) +@pytest.mark.parametrize('region_type', [str, tuple, list]) +def test_vlayout(lcfg, region_type): + nplots = 7 + layout = RendererLayout(lcfg, nplots) + + assert layout.ncols == 3 + assert layout.nrows == 3 + + regions = layout.arrange(lambda row, col: region_type((row, col))) + assert len(regions) == nplots + + assert regions[0] == region_type((0, 0)) + assert regions[2] == region_type((2, 0)) + assert regions[3] == region_type((0, 1)) + assert regions[6] == region_type((0, 2)) + + +def test_renderer_layout(): + # 2 columns + cfg = RendererConfig(WIDTH, HEIGHT) + lcfg = LayoutConfig(ncols=2) + nplots = 15 + + r = MatplotlibRenderer(cfg, lcfg, nplots) + + # 2 columns, 8 rows + assert r.layout.ncols == 2 + assert r.layout.nrows == 8 diff --git a/tests/test_renderer.py b/tests/test_renderer.py index 9d22f8d..f557c43 100644 --- a/tests/test_renderer.py +++ b/tests/test_renderer.py @@ -4,93 +4,12 @@ from matplotlib.colors import to_rgb from ovgenpy.channel import ChannelConfig from ovgenpy.outputs import RGB_DEPTH -from ovgenpy.renderer import RendererConfig, MatplotlibRenderer, LayoutConfig, \ - RendererLayout +from ovgenpy.renderer import RendererConfig, MatplotlibRenderer +from ovgenpy.layout import LayoutConfig WIDTH = 640 HEIGHT = 360 - -def test_config(): - with pytest.raises(ValueError): - LayoutConfig(nrows=1, ncols=1) - - one_col = LayoutConfig(ncols=1) - assert one_col - - one_row = LayoutConfig(nrows=1) - assert one_row - - default = LayoutConfig() - assert default.ncols == 1 # Should default to single-column layout - assert default.nrows is None - assert default.orientation == 'h' - - -@pytest.mark.parametrize('lcfg', [ - LayoutConfig(ncols=2), - LayoutConfig(nrows=8), -]) -@pytest.mark.parametrize('region_type', [str, tuple, list]) -def test_hlayout(lcfg, region_type): - nplots = 15 - layout = RendererLayout(lcfg, nplots) - - assert layout.ncols == 2 - assert layout.nrows == 8 - - regions = layout.arrange(lambda row, col: region_type((row, col))) - assert len(regions) == nplots - - assert regions[0] == region_type((0, 0)) - assert regions[1] == region_type((0, 1)) - assert regions[2] == region_type((1, 0)) - m = nplots - 1 - assert regions[m] == region_type((m // 2, m % 2)) - - -@pytest.mark.parametrize('lcfg', [ - LayoutConfig(ncols=3, orientation='v'), - LayoutConfig(nrows=3, orientation='v'), -]) -@pytest.mark.parametrize('region_type', [str, tuple, list]) -def test_vlayout(lcfg, region_type): - nplots = 7 - layout = RendererLayout(lcfg, nplots) - - assert layout.ncols == 3 - assert layout.nrows == 3 - - regions = layout.arrange(lambda row, col: region_type((row, col))) - assert len(regions) == nplots - - assert regions[0] == region_type((0, 0)) - assert regions[2] == region_type((2, 0)) - assert regions[3] == region_type((0, 1)) - assert regions[6] == region_type((0, 2)) - - -def test_renderer(): - """ - TODO check image output using: - https://matplotlib.org/devel/testing.html#writing-an-image-comparison-test - - https://stackoverflow.com/a/27950953 - "[I]mage comparison tests end up bring more trouble than they are worth" - """ - - # 2 columns - cfg = RendererConfig(WIDTH, HEIGHT) - lcfg = LayoutConfig(ncols=2) - nplots = 15 - - r = MatplotlibRenderer(cfg, lcfg, nplots) - - # 2 columns, 8 rows - assert r.layout.ncols == 2 - assert r.layout.nrows == 8 - - ALL_ZEROS = np.array([0,0]) all_colors = pytest.mark.parametrize('bg_str,fg_str', [ From 60e465841390fd9ff0743c245c75105964806e08 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Sat, 3 Nov 2018 23:20:55 -0700 Subject: [PATCH 3/5] Add Renderer abstract class --- ovgenpy/renderer.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/ovgenpy/renderer.py b/ovgenpy/renderer.py index 7da88bb..5bf418c 100644 --- a/ovgenpy/renderer.py +++ b/ovgenpy/renderer.py @@ -1,10 +1,11 @@ +from abc import ABC, abstractmethod from typing import Optional, List, TYPE_CHECKING, Any import matplotlib import numpy as np from ovgenpy.config import register_config -from ovgenpy.layout import RendererLayout +from ovgenpy.layout import RendererLayout, LayoutConfig from ovgenpy.outputs import RGB_DEPTH from ovgenpy.util import coalesce @@ -39,7 +40,23 @@ class RendererConfig: create_window: bool = False -class MatplotlibRenderer: +class Renderer(ABC): + def __init__(self, cfg: RendererConfig, lcfg: 'LayoutConfig', nplots: int): + self.cfg = cfg + self.nplots = nplots + self.layout = RendererLayout(lcfg, nplots) + + @abstractmethod + def set_colors(self, channel_cfgs: List['ChannelConfig']) -> None: ... + + @abstractmethod + def render_frame(self, datas: List[np.ndarray]) -> None: ... + + @abstractmethod + def get_frame(self) -> bytes: ... + + +class MatplotlibRenderer(Renderer): """ Renderer backend which takes data and produces images. Does not touch Wave or Channel. @@ -62,17 +79,15 @@ class MatplotlibRenderer: DPI = 96 - def __init__(self, cfg: RendererConfig, lcfg: 'LayoutConfig', nplots: int): - self.cfg = cfg - self.nplots = nplots - self.layout = RendererLayout(lcfg, nplots) + def __init__(self, *args, **kwargs): + Renderer.__init__(self, *args, **kwargs) # Flat array of nrows*ncols elements, ordered by cfg.rows_first. self._fig: 'Figure' = None self._axes: List['Axes'] = None # set by set_layout() self._lines: List['Line2D'] = None # set by render_frame() first call - self._line_colors: List = [None] * nplots + self._line_colors: List = [None] * self.nplots self._set_layout() # mutates self @@ -180,4 +195,3 @@ class MatplotlibRenderer: return buffer_rgb - From 5c7db2786283ed426db7a77bc49f844010b9c484 Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Mon, 5 Nov 2018 15:30:06 -0800 Subject: [PATCH 4/5] Improve error message of test_renderer If the foreground color is 136 instead of the right color, this corresponds to the global foreground color #888888, which means the per-channel foreground color wasn't applied. --- tests/test_renderer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_renderer.py b/tests/test_renderer.py index f557c43..56ecab9 100644 --- a/tests/test_renderer.py +++ b/tests/test_renderer.py @@ -72,7 +72,8 @@ def verify(r: MatplotlibRenderer, bg_str, fg_str): assert (frame_colors[0] == bg_u8).all() # Ensure foreground is present - assert np.prod(frame_colors == fg_u8, axis=-1).any() + assert np.prod(frame_colors == fg_u8, axis=-1).any(), \ + 'incorrect foreground, it might be 136 = #888888' assert (np.amax(frame_colors, axis=0) == np.maximum(bg_u8, fg_u8)).all() assert (np.amin(frame_colors, axis=0) == np.minimum(bg_u8, fg_u8)).all() From 88a79a97e817c68e524039fac673067e999a380f Mon Sep 17 00:00:00 2001 From: nyanpasu64 Date: Mon, 5 Nov 2018 15:45:38 -0800 Subject: [PATCH 5/5] Remove Renderer.set_colors(), move into constructor Makes it simpler to create an impl which constructs all canvases within __init__, not on first frame. --- ovgenpy/ovgenpy.py | 4 ++-- ovgenpy/renderer.py | 28 +++++++++++----------------- tests/test_layout.py | 2 +- tests/test_output.py | 2 +- tests/test_renderer.py | 10 +++++----- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/ovgenpy/ovgenpy.py b/ovgenpy/ovgenpy.py index d0ccb93..2ccc445 100644 --- a/ovgenpy/ovgenpy.py +++ b/ovgenpy/ovgenpy.py @@ -140,8 +140,8 @@ class Ovgen: yield def _load_renderer(self): - renderer = MatplotlibRenderer(self.cfg.render, self.cfg.layout, self.nchan) - renderer.set_colors(self.cfg.channels) + renderer = MatplotlibRenderer(self.cfg.render, self.cfg.layout, self.nchan, + self.cfg.channels) return renderer def play(self): diff --git a/ovgenpy/renderer.py b/ovgenpy/renderer.py index 5bf418c..81bbb2d 100644 --- a/ovgenpy/renderer.py +++ b/ovgenpy/renderer.py @@ -41,13 +41,21 @@ class RendererConfig: class Renderer(ABC): - def __init__(self, cfg: RendererConfig, lcfg: 'LayoutConfig', nplots: int): + def __init__(self, cfg: RendererConfig, lcfg: 'LayoutConfig', nplots: int, + channel_cfgs: Optional[List['ChannelConfig']]): self.cfg = cfg self.nplots = nplots self.layout = RendererLayout(lcfg, nplots) - @abstractmethod - def set_colors(self, channel_cfgs: List['ChannelConfig']) -> None: ... + # Load line colors. + if channel_cfgs is not None: + if len(channel_cfgs) != self.nplots: + raise ValueError( + f"cannot assign {len(channel_cfgs)} colors to {self.nplots} plots" + ) + self._line_colors = [cfg.line_color for cfg in channel_cfgs] + else: + self._line_colors = [None] * self.nplots @abstractmethod def render_frame(self, datas: List[np.ndarray]) -> None: ... @@ -87,8 +95,6 @@ class MatplotlibRenderer(Renderer): self._axes: List['Axes'] = None # set by set_layout() self._lines: List['Line2D'] = None # set by render_frame() first call - self._line_colors: List = [None] * self.nplots - self._set_layout() # mutates self def _set_layout(self) -> None: @@ -130,18 +136,6 @@ class MatplotlibRenderer(Renderer): if self.cfg.create_window: plt.show(block=False) - def set_colors(self, channel_cfgs: List['ChannelConfig']): - if len(channel_cfgs) != self.nplots: - raise ValueError( - f"cannot assign {len(channel_cfgs)} colors to {self.nplots} plots" - ) - - if self._lines is not None: - raise ValueError( - f'cannot set line colors after calling render_frame()' - ) - self._line_colors = [cfg.line_color for cfg in channel_cfgs] - def render_frame(self, datas: List[np.ndarray]) -> None: ndata = len(datas) if self.nplots != ndata: diff --git a/tests/test_layout.py b/tests/test_layout.py index 949a3c9..6490f02 100644 --- a/tests/test_layout.py +++ b/tests/test_layout.py @@ -70,7 +70,7 @@ def test_renderer_layout(): lcfg = LayoutConfig(ncols=2) nplots = 15 - r = MatplotlibRenderer(cfg, lcfg, nplots) + r = MatplotlibRenderer(cfg, lcfg, nplots, None) # 2 columns, 8 rows assert r.layout.ncols == 2 diff --git a/tests/test_output.py b/tests/test_output.py index f0ad4e2..115c667 100644 --- a/tests/test_output.py +++ b/tests/test_output.py @@ -19,7 +19,7 @@ NULL_CFG = FFmpegOutputConfig(None, '-f null') def test_render_output(): """ Ensure rendering to output does not raise exceptions. """ - renderer = MatplotlibRenderer(CFG.render, CFG.layout, nplots=1) + renderer = MatplotlibRenderer(CFG.render, CFG.layout, nplots=1, channel_cfgs=None) out: FFmpegOutput = NULL_CFG(CFG) renderer.render_frame([ALL_ZEROS]) diff --git a/tests/test_renderer.py b/tests/test_renderer.py index 56ecab9..51cfe5e 100644 --- a/tests/test_renderer.py +++ b/tests/test_renderer.py @@ -32,13 +32,13 @@ def test_default_colors(bg_str, fg_str): lcfg = LayoutConfig() nplots = 1 - r = MatplotlibRenderer(cfg, lcfg, nplots) + r = MatplotlibRenderer(cfg, lcfg, nplots, None) verify(r, bg_str, fg_str) # Ensure default ChannelConfig(line_color=None) does not override line color - r = MatplotlibRenderer(cfg, lcfg, nplots) chan = ChannelConfig(wav_path='') - r.set_colors([chan] * nplots) + channels = [chan] * nplots + r = MatplotlibRenderer(cfg, lcfg, nplots, channels) verify(r, bg_str, fg_str) @@ -54,9 +54,9 @@ def test_line_colors(bg_str, fg_str): lcfg = LayoutConfig() nplots = 1 - r = MatplotlibRenderer(cfg, lcfg, nplots) chan = ChannelConfig(wav_path='', line_color=fg_str) - r.set_colors([chan] * nplots) + channels = [chan] * nplots + r = MatplotlibRenderer(cfg, lcfg, nplots, channels) verify(r, bg_str, fg_str)