diff --git a/pygmt/params/pattern.py b/pygmt/params/pattern.py index 33c83a569cd..7740352c35d 100644 --- a/pygmt/params/pattern.py +++ b/pygmt/params/pattern.py @@ -37,7 +37,7 @@ class Pattern(BaseParam): The pattern to use. It can be specified in two forms: - An integer in the range of 1-90, corresponding to one of 90 predefined 64x64 - bit-patterns + bit-patterns. [Default is 1]. - Name of a 1-, 8-, or 24-bit image raster file, to create customized, repeating images using image raster files. dpi @@ -69,7 +69,7 @@ class Pattern(BaseParam): >>> fig.show() """ - pattern: int | PathLike + pattern: int | PathLike = 1 dpi: int | None = None bgcolor: str | None = None fgcolor: str | None = None @@ -80,7 +80,10 @@ def _validate(self): Validate the parameters. """ # Integer pattern number must be in the range 1-90. - if isinstance(self.pattern, int) and not (1 <= self.pattern <= 90): + if not ( + isinstance(self.pattern, PathLike) + or (isinstance(self.pattern, int) and 1 <= self.pattern <= 90) + ): raise GMTValueError( self.pattern, description="pattern number", diff --git a/pygmt/tests/test_params_pattern.py b/pygmt/tests/test_params_pattern.py index 713503bb008..51d768693ea 100644 --- a/pygmt/tests/test_params_pattern.py +++ b/pygmt/tests/test_params_pattern.py @@ -35,8 +35,10 @@ def test_pattern(): def test_pattern_invalid_pattern(): """ - Test that an invalid pattern number raises a GMTValueError. + Test that an invalid pattern value or number raises a GMTValueError. """ + with pytest.raises(GMTValueError): + _ = Pattern(None) # Value that is neither int nor PathLike with pytest.raises(GMTValueError): _ = str(Pattern(0)) with pytest.raises(GMTValueError):