"""Test cases for Base 64.""" from .. import util import os CURRENT_DIR = os.path.abspath(os.path.dirname(__file__)) class TestB64(util.MdCase): """Test Base 64.""" extension = ['pymdownx.b64'] extension_configs = { "pymdownx.b64": { "base_path": CURRENT_DIR } } def test_in_script(self): """Test that we do not parse image in script.""" self.check_markdown( r''' ''', r''' ''', True ) def test_comment(self): """Don't convert image in comment.""" self.check_markdown( '', '', True ) def test_relative_path(self): """Test relative path.""" self.check_markdown( '![picture](../test_extensions/_assets/bg.png)', '

picture

', # noqa: E501 True ) def test_relative_path_outside(self): """Test relative path.""" self.check_markdown( '![picture](../extensions/_assets/bg.png)', '

picture

', True ) def test_cache_busting(self): """Test we can convert cache busted images.""" self.check_markdown( '![picture with cache busting](_assets/bg.png?v2)', '

picture with cache busting

', # noqa: E501 True ) def test_does_not_exist(self): """Test handling of file that does not exist.""" self.check_markdown( '![Some windows path link](file:///c:/does_not_exist.png)', '

Some windows path link

', True ) class TestB64Unrestrict(util.MdCase): """Test Base 64 with unrestricted path.""" extension = ['pymdownx.b64'] extension_configs = { "pymdownx.b64": { "base_path": CURRENT_DIR, "restrict_path": False } } def test_relative_path_outside(self): """Test relative path.""" self.check_markdown( '![picture](../extensions/_assets/bg.png)', '

picture

', # noqa: E501 True ) class TestB64RestrictRoot(util.MdCase): """Test Base 64 with restricted path, but root adjusted to contained it.""" extension = ['pymdownx.b64'] extension_configs = { "pymdownx.b64": { "root_path": os.path.dirname(CURRENT_DIR), "base_path": CURRENT_DIR, "restrict_path": True } } def test_relative_path_outside(self): """Test relative path.""" self.check_markdown( '![picture](../extensions/_assets/bg.png)', '

picture

', # noqa: E501 True )