|
1 | 1 | from __future__ import absolute_import
|
2 | 2 |
|
3 | 3 | from unittest import TestCase
|
| 4 | +import pytest |
4 | 5 | from plotly.graph_objs import (
|
5 | 6 | Annotation,
|
6 | 7 | Annotations,
|
@@ -1934,3 +1935,73 @@ def test_if_passed_figure(self):
|
1934 | 1935 | fig2sp = subplots.make_subplots(2, 2)
|
1935 | 1936 | assert id(fig2sp) != id(figsp)
|
1936 | 1937 | assert fig2sp.layout == figsp.layout
|
| 1938 | + |
| 1939 | + |
| 1940 | +def test_make_subplots_spacing_error(): |
| 1941 | + # check exception describing maximum value for horizontal_spacing or |
| 1942 | + # vertical_spacing is raised when spacing exceeds that value |
| 1943 | + with pytest.raises( |
| 1944 | + ValueError, |
| 1945 | + match=( |
| 1946 | + "^%s spacing cannot be greater than \(1 / \(%s - 1\)\) = %f.$" |
| 1947 | + % ("Vertical", "rows", 0.02) |
| 1948 | + ).replace(".", "\."), |
| 1949 | + ): |
| 1950 | + fig = subplots.make_subplots(51, 1, vertical_spacing=0.0201) |
| 1951 | + with pytest.raises( |
| 1952 | + ValueError, |
| 1953 | + match=( |
| 1954 | + "^%s spacing cannot be greater than \(1 / \(%s - 1\)\) = %f.$" |
| 1955 | + % ("Horizontal", "cols", 0.02) |
| 1956 | + ).replace(".", "\."), |
| 1957 | + ): |
| 1958 | + fig = subplots.make_subplots(1, 51, horizontal_spacing=0.0201) |
| 1959 | + try: |
| 1960 | + fig = subplots.make_subplots(51, 1, vertical_spacing=0.0200) |
| 1961 | + except ValueError: |
| 1962 | + # This shouldn't happen so we assert False to force failure |
| 1963 | + assert False |
| 1964 | + try: |
| 1965 | + fig = subplots.make_subplots(1, 51, horizontal_spacing=0.0200) |
| 1966 | + except ValueError: |
| 1967 | + # This shouldn't happen so we assert False to force failure |
| 1968 | + assert False |
| 1969 | + # make sure any value between 0 and 1 works for horizontal_spacing if cols is 1 |
| 1970 | + try: |
| 1971 | + fig = subplots.make_subplots(1, 1, horizontal_spacing=0) |
| 1972 | + except ValueError: |
| 1973 | + # This shouldn't happen so we assert False to force failure |
| 1974 | + assert False |
| 1975 | + try: |
| 1976 | + fig = subplots.make_subplots(1, 1, horizontal_spacing=1) |
| 1977 | + except ValueError: |
| 1978 | + # This shouldn't happen so we assert False to force failure |
| 1979 | + assert False |
| 1980 | + # make sure any value between 0 and 1 works for horizontal_spacing if cols is 1 |
| 1981 | + try: |
| 1982 | + fig = subplots.make_subplots(1, 1, horizontal_spacing=0) |
| 1983 | + except ValueError: |
| 1984 | + # This shouldn't happen so we assert False to force failure |
| 1985 | + assert False |
| 1986 | + # make sure any value between 0 and 1 works for horizontal_spacing if cols is 1 |
| 1987 | + try: |
| 1988 | + fig = subplots.make_subplots(1, 1, horizontal_spacing=1) |
| 1989 | + except ValueError: |
| 1990 | + # This shouldn't happen so we assert False to force failure |
| 1991 | + assert False |
| 1992 | + with pytest.raises( |
| 1993 | + ValueError, match="^Horizontal spacing must be between 0 and 1\.$" |
| 1994 | + ): |
| 1995 | + fig = subplots.make_subplots(1, 1, horizontal_spacing=-0.01) |
| 1996 | + with pytest.raises( |
| 1997 | + ValueError, match="^Horizontal spacing must be between 0 and 1\.$" |
| 1998 | + ): |
| 1999 | + fig = subplots.make_subplots(1, 1, horizontal_spacing=1.01) |
| 2000 | + with pytest.raises( |
| 2001 | + ValueError, match="^Vertical spacing must be between 0 and 1\.$" |
| 2002 | + ): |
| 2003 | + fig = subplots.make_subplots(1, 1, vertical_spacing=-0.01) |
| 2004 | + with pytest.raises( |
| 2005 | + ValueError, match="^Vertical spacing must be between 0 and 1\.$" |
| 2006 | + ): |
| 2007 | + fig = subplots.make_subplots(1, 1, vertical_spacing=1.01) |
0 commit comments