How to use the imgkit.IMGKit function in imgkit

To help you get started, we’ve selected a few imgkit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jarrekk / imgkit / tests / imgkit-tests.py View on Github external
def test_file_source_with_path(self):
        r = imgkit.IMGKit('test', 'string')
        with io.open('fixtures/example.css') as f:
            self.assertTrue(r.source.isFile(path=f))
        with codecs.open('fixtures/example.css', encoding='UTF-8') as f:
            self.assertTrue(r.source.isFile(path=f))
github jarrekk / imgkit / tests / imgkit-tests.py View on Github external
def test_imgkit_meta_tags_in_bad_markup(self):
        body = """
        
          
            
            
          
          <br>
        
        """

        r = imgkit.IMGKit(body, 'string')
        command = r.command()
        self.assertEqual(command[command.index('--format') + 1], 'jpg')
        self.assertEqual(command[command.index('--orientation') + 1], 'Landscape')
github jarrekk / imgkit / tests / imgkit-tests.py View on Github external
def test_options_parsing_with_tuple(self):
        options = {
            '--custom-header': [
                ('Accept-Encoding', 'gzip')
            ]
        }
        r = imgkit.IMGKit('html', 'string', options=options)
        command = r.command()
        idx1 = command.index('--custom-header')  # Raise exception in case of not found
        self.assertTrue(command[idx1 + 1] == 'Accept-Encoding')
        self.assertTrue(command[idx1 + 2] == 'gzip')
github jarrekk / imgkit / tests / imgkit-tests.py View on Github external
def test_multiple_stylesheet_adding_without_head_tag(self):
        css_files = ['fixtures/example.css', 'fixtures/example2.css']
        r = imgkit.IMGKit('Hai!', 'string',
                          options={'quiet': None}, css=css_files)

        css = []
        for css_file in css_files:
            with open(css_file) as f:
                css.append(f.read())

        r._prepend_css(css_files)
        self.assertIn('<style>%s</style>' % "\n".join(css), r.source.to_s())
github jarrekk / imgkit / tests / imgkit-tests.py View on Github external
def test_imgkit_meta_tags(self):
        body = """
        
          
            
            
          
        """

        r = imgkit.IMGKit(body, 'string')
        command = r.command()
        self.assertEqual(command[command.index('--format') + 1], 'jpg')
        self.assertEqual(command[command.index('--orientation') + 1], 'Landscape')
github jarrekk / imgkit / tests / imgkit-tests.py View on Github external
def test_lists_of_input_args(self):
        urls = ['http://ya.ru', 'http://google.com']
        paths = ['fixtures/example.html', 'fixtures/example.html']
        r = imgkit.IMGKit(urls, 'url')
        r2 = imgkit.IMGKit(paths, 'file')
        cmd = r.command()
        cmd2 = r2.command()
        self.assertEqual(cmd[-3:], ['http://ya.ru', 'http://google.com', '-'])
        self.assertEqual(cmd2[-3:], ['fixtures/example.html', 'fixtures/example.html', '-'])
github jarrekk / imgkit / tests / imgkit-tests.py View on Github external
def test_outline_options(self):
        options = {
            'outline': None,
            'outline-depth': 1
        }

        r = imgkit.IMGKit('ya.ru', 'url', options=options)
        cmd = r.command()
        # self.assertEqual(cmd[1:], ['--outline', '--outline-depth', '1', 'ya.ru', '-'])
        self.assertIn('--outline', cmd)
        self.assertEqual(cmd[cmd.index('--outline-depth') + 1], '1')
github jarrekk / imgkit / tests / imgkit-tests.py View on Github external
def test_skip_nonimgkit_tags(self):
        body = """
        
          
            
            
          
          <br>
        
        """

        r = imgkit.IMGKit(body, 'string')
        command = r.command()
        self.assertEqual(command[command.index('--orientation') + 1], 'Landscape')
github jarrekk / imgkit / tests / imgkit-tests.py View on Github external
def test_raise_error_with_invalid_file_path(self):
        paths = ['frongpath.html', 'wrongpath2.html']
        with self.assertRaises(IOError):
            imgkit.IMGKit('wrongpath.html', 'file')
        with self.assertRaises(IOError):
            imgkit.IMGKit(paths, 'file')
github jarrekk / imgkit / tests / imgkit-tests.py View on Github external
def test_cover_without_options(self):
        r = imgkit.IMGKit('html', 'string', cover='test.html')

        command = r.command()

        self.assertEqual(command[1], 'cover')
        self.assertEqual(command[2], 'test.html')