Exclude (system specific) absolute paths from test file and add a unittest that creates/tests absolute paths on-the-fly
This commit is contained in:
parent
902e112a96
commit
de1441fd58
2 changed files with 25 additions and 2 deletions
23
testscour.py
23
testscour.py
|
|
@ -2386,6 +2386,29 @@ class EmbedRasters(unittest.TestCase):
|
||||||
self.assertTrue(href.startswith('data:image/'),
|
self.assertTrue(href.startswith('data:image/'),
|
||||||
"Raster image from local path '" + href + "' not embedded.")
|
"Raster image from local path '" + href + "' not embedded.")
|
||||||
|
|
||||||
|
def test_raster_paths_local_absolute(self):
|
||||||
|
with open('unittests/raster-formats.svg', 'r') as f:
|
||||||
|
svg = f.read()
|
||||||
|
|
||||||
|
# create a reference string by scouring the original file with relative links
|
||||||
|
options = ScourOptions
|
||||||
|
options.infilename = 'unittests/raster-formats.svg'
|
||||||
|
reference_svg = scourString(svg, options)
|
||||||
|
|
||||||
|
# this will not always create formally valid paths but it'll check how robust our implementation is
|
||||||
|
# (the third path is invalid for sure because file: needs three slashes according to URI spec)
|
||||||
|
svg = svg.replace('raster.png',
|
||||||
|
'/' + os.path.abspath(os.path.dirname(__file__)) + '\\unittests\\raster.png')
|
||||||
|
svg = svg.replace('raster.gif',
|
||||||
|
'file:///' + os.path.abspath(os.path.dirname(__file__)) + '/unittests/raster.gif')
|
||||||
|
svg = svg.replace('raster.jpg',
|
||||||
|
'file:/' + os.path.abspath(os.path.dirname(__file__)) + '/unittests/raster.jpg')
|
||||||
|
|
||||||
|
svg = scourString(svg)
|
||||||
|
|
||||||
|
self.assertEqual(svg, reference_svg,
|
||||||
|
"Raster images from absolute local paths not properly embedded.")
|
||||||
|
|
||||||
@unittest.skipIf(_ping('raw.githubusercontent.com') != 0, "Remote server not reachable.")
|
@unittest.skipIf(_ping('raw.githubusercontent.com') != 0, "Remote server not reachable.")
|
||||||
def test_raster_paths_remote(self):
|
def test_raster_paths_remote(self):
|
||||||
doc = scourXmlFile('unittests/raster-paths-remote.svg')
|
doc = scourXmlFile('unittests/raster-paths-remote.svg')
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
<image x="10" y="90" width="150" height="50" xlink:href="./raster.png"/>
|
<image x="10" y="90" width="150" height="50" xlink:href="./raster.png"/>
|
||||||
<image x="10" y="150" width="150" height="50" xlink:href="../unittests/raster.png"/>
|
<image x="10" y="150" width="150" height="50" xlink:href="../unittests/raster.png"/>
|
||||||
<!-- path can also be absolute but this will obviously not work across systems -->
|
<!-- path can also be absolute but this will obviously not work across systems -->
|
||||||
<image x="10" y="210" width="150" height="50" xlink:href="/E:/Temp/Scour/scour.git/unittests/raster.png"/>
|
<!--<image x="10" y="210" width="150" height="50" xlink:href="/E:/Temp/Scour/scour.git/unittests/raster.png"/>-->
|
||||||
</g>
|
</g>
|
||||||
<g transform="translate(160)">
|
<g transform="translate(160)">
|
||||||
<text x="10" y="20">Local files (file: protocol)</text>
|
<text x="10" y="20">Local files (file: protocol)</text>
|
||||||
|
|
@ -14,6 +14,6 @@
|
||||||
<image x="10" y="90" width="150" height="50" xlink:href="file:./raster.png"/>
|
<image x="10" y="90" width="150" height="50" xlink:href="file:./raster.png"/>
|
||||||
<image x="10" y="150" width="150" height="50" xlink:href="file:../unittests/raster.png"/>
|
<image x="10" y="150" width="150" height="50" xlink:href="file:../unittests/raster.png"/>
|
||||||
<!-- path can also be absolute but this will obviously not work across systems -->
|
<!-- path can also be absolute but this will obviously not work across systems -->
|
||||||
<image x="10" y="210" width="150" height="50" xlink:href="file:///E:/Temp/Scour/scour.git/unittests/raster.png"/>
|
<!--<image x="10" y="210" width="150" height="50" xlink:href="file:///E:/Temp/Scour/scour.git/unittests/raster.png"/>-->
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Loading…
Add table
Add a link
Reference in a new issue