Beispiel #1
0
 def test_unknown_type_file_path(self):
     with tempfile.NamedTemporaryFile() as non_image:
         non_image.write(b'Hello')
         non_image.flush()
         with self.assertRaisesRegex(ValueError,
                                     'not able to determine file type'):
             pybadges._embed_image(non_image.name)
Beispiel #2
0
 def test_text_file_path(self):
     with tempfile.NamedTemporaryFile(suffix='.txt') as non_image:
         non_image.write(b'Hello')
         non_image.flush()
         with self.assertRaisesRegex(ValueError,
                                     'expected an image, got "text"'):
             pybadges._embed_image(non_image.name)
Beispiel #3
0
 def test_png_file_path(self):
     with tempfile.NamedTemporaryFile() as png:
         png.write(PNG_IMAGE)
         png.flush()
         self.assertEqual(pybadges._embed_image(png.name),
                          'data:image/png;base64,' + PNG_IMAGE_B64)
Beispiel #4
0
 def test_svg_file_path(self):
     image_path = os.path.abspath(
         os.path.join(TEST_DIR, 'golden-images', 'build-failure.svg'))
     self.assertRegex(pybadges._embed_image(image_path),
                      r'^data:image/svg(\+xml)?;base64,')
Beispiel #5
0
 def test_not_image_url(self):
     with self.assertRaisesRegex(ValueError,
                                 'expected an image, got "text"'):
         pybadges._embed_image('http://www.google.com/')
Beispiel #6
0
 def test_http_url(self):
     url = 'https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/python.svg'
     self.assertRegex(pybadges._embed_image(url),
                      r'^data:image/svg(\+xml)?;base64,')
Beispiel #7
0
 def test_data_url(self):
     url = 'data:image/png;base64,' + PNG_IMAGE_B64
     self.assertEqual(url, pybadges._embed_image(url))
Beispiel #8
0
    def test_file_url(self):
        image_path = os.path.abspath(
            os.path.join(TEST_DIR, 'golden-images', 'build-failure.svg'))

        with self.assertRaisesRegex(ValueError, 'unsupported scheme "file"'):
            pybadges._embed_image(pathlib.Path(image_path).as_uri())