Beispiel #1
0
 def test_03_error_debug(self):
     settings.DEBUG = True
     o = Optimizer()
     o.filepath = '/absolute/path/filename.png'
     params = o.get_params_for(o.filepath)
     o.cmdline = o.cmdline_template % params
     o.dest_path = o.dest_path_template % params
     o.retval = 1
     o.stdout = 'test stdout content\n'
     o.stderr = 'test stderr content\n'
     try:
         o.error('test subject')
         self.fail('o.error did not raise exception')
     except Exception, e:
         assert isinstance(e, OptimizerError), e
         self.assertEquals(
             e.message,
             'Original PNG path: /absolute/path/filename.png\n'
             'Optimized PNG path: /absolute/path/filename-optimized.png\n'
             'Optimizer command line:'
             ' python ../cairotext/test_optimizer.py'
             ' /absolute/path/filename.png\n'
             'Optimizer return value: 1\n'
             'test stdout content\n'
             'test stderr content\n')
Beispiel #2
0
 def test_01_params(self):
     o = Optimizer()
     params = o.get_params_for('/absolute/path/filename.png')
     self.assertEqual(params, {'directory': '/absolute/path',
                               'path': '/absolute/path/filename.png',
                               'ext': 'png',
                               'name': 'filename'})
Beispiel #3
0
 def test_05_optimize(self):
     directory = mkdtemp()
     filepath = join(directory, 'test.png')
     file(filepath, 'w').write('dummy')
     o = Optimizer()
     o.optimize(filepath)
     self.assertEqual(len(mail.outbox), 0)
     self.assertEquals(file(filepath).read(), TEST_IMAGE)
     remove(filepath)
     rmdir(directory)
Beispiel #4
0
 def test_02_error(self):
     o = Optimizer()
     o.filepath = '/absolute/path/filename.png'
     params = o.get_params_for(o.filepath)
     o.cmdline = o.cmdline_template % params
     o.dest_path = o.dest_path_template % params
     o.retval = 1
     o.stdout = 'test stdout content\n'
     o.stderr = 'test stderr content\n'
     o.error('test subject')
     self.assertEqual(len(mail.outbox), 1)
     m = mail.outbox[0]
     self.assertEqual(
         m.subject, '[Django] test subject')
     self.assertEqual(
         m.body,
         'Original PNG path: /absolute/path/filename.png\n'
         'Optimized PNG path: /absolute/path/filename-optimized.png\n'
         'Optimizer command line:'
         ' python ../cairotext/test_optimizer.py'
         ' /absolute/path/filename.png\n'
         'Optimizer return value: 1\n'
         'test stdout content\n'
         'test stderr content\n')