<commit_before>#!/bin/env python
#copyright ReportLab Inc. 2000
#see license.txt for license details
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/pdfgen/test/test_invariant.py?cvsroot=reportlab
#$Header: /tmp/reportlab/reportlab/test/test_invariant.py,v 1.5 2004/01/20 22:50:32 andy_robinson Exp $
__version__=''' $Id'''
__doc__="""Verfy that if in invariant mode, repeated runs
make identical file.  This does NOT test across platforms
or python versions, only a user can do that :-)"""

from reportlab.test import unittest
from reportlab.test.utils import makeSuiteForClasses
from reportlab.pdfgen.canvas import Canvas
filename = 'test_invariant.pdf'

class InvarTestCase(unittest.TestCase):
    "Simplest test that makes PDF"
    def test(self):

        c = Canvas(filename, invariant=1, pageCompression=0)
        c.setFont('Helvetica-Bold', 36)
        c.drawString(100,700, 'Hello World')
        c.drawImage('pythonpowered.gif',100,600)
        c.save()

        raw1 = open(filename, 'rb').read()

        c = Canvas(filename, invariant=1, pageCompression=0)
        c.setFont('Helvetica-Bold', 36)
        c.drawString(100,700, 'Hello World')
        c.drawImage('pythonpowered.gif',100,600)
        c.save()

        raw2 = open(filename, 'rb').read()

        assert raw1 == raw2, 'repeated runs differ!'



def makeSuite():
    return makeSuiteForClasses(InvarTestCase)


#noruntests
if __name__ == "__main__":
    # add some diagnostics, useful in invariant tests
    import sys, md5, os
    verbose = ('-v' in sys.argv)
    unittest.TextTestRunner().run(makeSuite())
    if verbose:
        #tell us about the file we produced
        fileSize = os.stat(filename)[6]
        raw = open(filename,'rb').read()
        digest = md5.md5(raw).hexdigest()
        major, minor = sys.version_info[0:2]
        print 'test_invariant.pdf on %s (Python %d.%d):\n    %d bytes, digest %s' % (
            sys.platform, major, minor, fileSize, digest)<commit_msg>Now works in compact distro<commit_after>#!/bin/env python
#copyright ReportLab Inc. 2000
#see license.txt for license details
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/reportlab/pdfgen/test/test_invariant.py?cvsroot=reportlab
#$Header: /tmp/reportlab/reportlab/test/test_invariant.py,v 1.6 2004/03/23 15:43:13 rgbecker Exp $
__version__=''' $Id'''
__doc__="""Verfy that if in invariant mode, repeated runs
make identical file.  This does NOT test across platforms
or python versions, only a user can do that :-)"""

from reportlab.test import unittest
from reportlab.test.utils import makeSuiteForClasses
from reportlab.pdfgen.canvas import Canvas
filename = 'test_invariant.pdf'

class InvarTestCase(unittest.TestCase):
    "Simplest test that makes PDF"
    def test(self):

        import os
        c = Canvas(filename, invariant=1, pageCompression=0)
        c.setFont('Helvetica-Bold', 36)
        c.drawString(100,700, 'Hello World')
        gif = os.path.join(os.path.dirname(unittest.__file__),'pythonpowered.gif')
        c.drawImage(gif,100,600)
        c.save()

        raw1 = open(filename, 'rb').read()

        c = Canvas(filename, invariant=1, pageCompression=0)
        c.setFont('Helvetica-Bold', 36)
        c.drawString(100,700, 'Hello World')
        c.drawImage(gif,100,600)
        c.save()

        raw2 = open(filename, 'rb').read()
        assert raw1 == raw2, 'repeated runs differ!'

def makeSuite():
    return makeSuiteForClasses(InvarTestCase)


#noruntests
if __name__ == "__main__":
    # add some diagnostics, useful in invariant tests
    import sys, md5, os
    verbose = ('-v' in sys.argv)
    unittest.TextTestRunner().run(makeSuite())
    if verbose:
        #tell us about the file we produced
        fileSize = os.stat(filename)[6]
        raw = open(filename,'rb').read()
        digest = md5.md5(raw).hexdigest()
        major, minor = sys.version_info[0:2]
        print 'test_invariant.pdf on %s (Python %d.%d):\n    %d bytes, digest %s' % (
            sys.platform, major, minor, fileSize, digest)

{'fraction_non_alphanumeric': 0.12703905091448345, 'fraction_numerical': 0.03064755313890262, 'mean_word_length': 3.342274678111588, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1664300', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1289, 'n_words': 331}