def test_overlay_array():
    plot = Plot()
    lst = [1, 2, 3]
    plot.overlay_array(lst)
    assert plot.command_and_arguments == {
        'command': 'overlay_array',
        'arguments': [memoryview(np.array(lst, dtype=np.float32))],
    }
def test_overlay_href(traitlet_set_mock):
    plot = Plot()
    plot.overlay_href('bar|baz')
    assert traitlet_set_mock.call_count == 2
    for call_args in traitlet_set_mock.call_args_list:
        assert call_args[0][0]['command'] == 'overlay_href'
        assert len(call_args[0][0]['arguments']) == 1
        assert call_args[0][0]['arguments'][0] in ('bar', 'baz')
def test_getattr_change_settings():
    plot = Plot()
    options = {'autol': 1000}
    plot.change_settings(options)
    assert plot.command_and_arguments == {
        'command': 'change_settings',
        'arguments': [options]
    }
def test_overlay_array_numpy():
    plot = Plot()
    lst = np.array([1, 2, 3])
    plot.overlay_array(lst)
    assert plot.command_and_arguments == {
        'command': 'overlay_array',
        'arguments': [memoryview(lst.astype(np.float32))],
    }
def test_instance_level_resolver():
    from jupyter_sigplot.sigplot import Plot

    def to_foo(_):
        return 'foo'

    # If a single path resolver makes it all the way through the prepare step,
    # we assume that other tests ensure more complicated cases do, too.

    # Resolver specified in constructor
    p = Plot(path_resolvers=[to_foo])
    p.overlay_href('baz')
    assert p.path_resolvers == [to_foo]
    assert p.command_and_arguments == {
        'command': 'overlay_href',
        'arguments': ['foo']
    }

    # Resolver specified after construction
    p = Plot()
    p.path_resolvers = [to_foo]
    p.overlay_href('quux')
    assert p.path_resolvers == [to_foo]
    assert p.command_and_arguments == {
        'command': 'overlay_href',
        'arguments': ['foo']
    }
def test_class_level_resolver(traitlet_set_mock):
    from jupyter_sigplot.sigplot import Plot

    def to_foo(_):
        return 'foo'

    Plot.path_resolvers = [to_foo]

    # Resolver applied post constructor
    p = Plot()
    p.overlay_href('baz|quux.mat')
    assert traitlet_set_mock.call_count == 2
    for call_args in traitlet_set_mock.call_args_list:
        assert call_args[0][0]['command'] == 'overlay_href'
        assert len(call_args[0][0]['arguments']) == 1
        assert call_args[0][0]['arguments'][0] == 'foo'
def test_available_commands():
    plot = Plot()
    available_commands = [
        'change_settings',
        'overlay_href',
        'overlay_array',
    ]
    assert plot.available_commands == available_commands
def test_empty_object():
    plot = Plot()
    # instance variables
    assert plot.data_dir == ''
    assert plot.path_resolvers == []
    # traitlets
    assert plot.command_and_arguments == {}
    assert plot.plot_options == {}
    assert plot.progress == 0.0
    assert not plot.done
def test_non_empty_object():
    data_dir = "/tmp"
    path_resolvers = ["/data"]
    options = {'noyaxis': True, 'noxaxis': True}
    plot = Plot(
        data_dir=data_dir,
        path_resolvers=path_resolvers,
        **options
    )
    # instance variables
    assert plot.data_dir == data_dir
    assert plot.path_resolvers == path_resolvers

    # traitlets
    assert plot.command_and_arguments == {}
    assert plot.plot_options == options
    assert plot.progress == 0.0
    assert not plot.done
def test_overlay_array_bad_type():
    plot = Plot()
    lst = ['foo', 'bar', 'baz']
    with pytest.raises(TypeError):
        plot.overlay_array(lst)
def test_attr_error():
    plot = Plot()
    with pytest.raises(AttributeError):
        plot.foobar('blah')
def test_UPPERCASE_getattr_change_settings():
    plot = Plot()
    options = {'autol': 1000}
    with pytest.raises(AttributeError):
        plot.CHANGE_SETTINGS(options)
def test_overlay_array_numpy_bad_dtype():
    plot = Plot()
    lst = np.array(['foo', 'bar', 'baz'])
    with pytest.raises(TypeError):
        plot.overlay_array(lst)