1#-----------------------------------------------------------------------------
2# Copyright (c) 2012 - 2021, Anaconda, Inc., and Bokeh Contributors.
3# All rights reserved.
4#
5# The full license is in the file LICENSE.txt, distributed with this software.
6#-----------------------------------------------------------------------------
7
8#-----------------------------------------------------------------------------
9# Boilerplate
10#-----------------------------------------------------------------------------
11import pytest ; pytest
12
13#-----------------------------------------------------------------------------
14# Imports
15#-----------------------------------------------------------------------------
16
17# Standard library imports
18import warnings
19
20# Bokeh imports
21from bokeh._testing.util.api import verify_all
22from bokeh.util.warnings import BokehDeprecationWarning, BokehUserWarning
23
24# Module under test
25import bokeh as b # isort:skip
26
27#-----------------------------------------------------------------------------
28# Setup
29#-----------------------------------------------------------------------------
30
31ALL =  (
32    '__version__',
33    'license',
34    'sampledata',
35)
36
37_LICENSE = """\
38Copyright (c) 2012 - 2021, Anaconda, Inc., and Bokeh Contributors
39All rights reserved.
40
41Redistribution and use in source and binary forms, with or without modification,
42are permitted provided that the following conditions are met:
43
44Redistributions of source code must retain the above copyright notice,
45this list of conditions and the following disclaimer.
46
47Redistributions in binary form must reproduce the above copyright notice,
48this list of conditions and the following disclaimer in the documentation
49and/or other materials provided with the distribution.
50
51Neither the name of Anaconda nor the names of any contributors
52may be used to endorse or promote products derived from this software
53without specific prior written permission.
54
55THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
56AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
58ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
59LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
60CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
61SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
62INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
63CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
65THE POSSIBILITY OF SUCH DAMAGE.
66
67"""
68
69#-----------------------------------------------------------------------------
70# General API
71#-----------------------------------------------------------------------------
72
73Test___all__ = verify_all(b, ALL)
74
75def test___version___type() -> None:
76    assert isinstance(b.__version__, str)
77
78def test___version___defined() -> None:
79    assert b.__version__ != 'unknown'
80
81def test_license(capsys) -> None:
82    b.license()
83    out, err = capsys.readouterr()
84    assert out == _LICENSE
85
86class TestWarnings:
87    @pytest.mark.parametrize('cat', (BokehDeprecationWarning, BokehUserWarning))
88    def test_bokeh_custom(self, cat) -> None:
89        r = warnings.formatwarning("message", cat, "line", "lineno")
90        assert r == "%s: %s\n" %(cat.__name__, "message")
91
92    def test_general_default(self) -> None:
93        r = warnings.formatwarning("message", RuntimeWarning, "line", "lineno")
94        assert r == "line:lineno: RuntimeWarning: message\n"
95
96    # TODO (bev) issue with this one test and 3.9 support PR
97    @pytest.mark.skip
98    def test_filters(self) -> None:
99        assert ('always', None, BokehUserWarning, None, 0) in warnings.filters
100        assert ('always', None, BokehDeprecationWarning, None, 0) in warnings.filters
101
102#-----------------------------------------------------------------------------
103# Dev API
104#-----------------------------------------------------------------------------
105
106#-----------------------------------------------------------------------------
107# Private API
108#-----------------------------------------------------------------------------
109
110#-----------------------------------------------------------------------------
111# Code
112#-----------------------------------------------------------------------------
113