示例#1
0
def main(pattern='test_*.py'):
    try:
        folder = os.path.dirname(__file__)
        assert folder
    except:
        folder = os.path.dirname(sys.argv[0]) or os.getcwd()
    #allow for Benn's "screwball cygwin distro":
    if folder == '':
        folder = '.'
    from reportlab.lib.utils import isSourceDistro
    haveSRC = isSourceDistro()

    def cleanup(folder,
                patterns=('*.pdf', '*.log', '*.svg', 'runAll.txt',
                          'test_*.txt', '_i_am_actually_a_*.*')):
        if not folder: return
        for pat in patterns:
            for filename in GlobDirectoryWalker(folder, pattern=pat):
                try:
                    os.remove(filename)
                except:
                    pass

    # special case for reportlab/test directory - clean up
    # all PDF & log files before starting run.  You don't
    # want this if reusing runAll anywhere else.
    if string.find(folder, 'reportlab' + os.sep + 'test') > -1: cleanup(folder)
    cleanup(outputfile(''))
    NI = []
    cleanOnly = '--clean' in sys.argv
    if not cleanOnly:
        testSuite = makeSuite(folder,
                              nonImportable=NI,
                              pattern=pattern + (not haveSRC and 'c' or ''))
        unittest.TextTestRunner().run(testSuite)
    if haveSRC: cleanup(folder, patterns=('*.pyc', '*.pyo'))
    if not cleanOnly:
        if NI:
            sys.stderr.write(
                '\n###################### the following tests could not be imported\n'
            )
            for f, tb in NI:
                print 'file: "%s"\n%s\n' % (f, string.join(tb, ''))
        printLocation()
示例#2
0
def main(pattern='test_*.py'):
    try:
        folder = os.path.dirname(__file__)
        assert folder
    except:
        folder = os.path.dirname(sys.argv[0]) or os.getcwd()
    #allow for Benn's "screwball cygwin distro":
    if folder == '':
        folder = '.'
    from reportlab.lib.utils import isSourceDistro
    haveSRC = isSourceDistro()

    def cleanup(folder,patterns=('*.pdf', '*.log','*.svg','runAll.txt', 'test_*.txt','_i_am_actually_a_*.*')):
        if not folder: return
        for pat in patterns:
            for filename in GlobDirectoryWalker(folder, pattern=pat):
                try:
                    os.remove(filename)
                except:
                    pass

    # special case for reportlab/test directory - clean up
    # all PDF & log files before starting run.  You don't
    # want this if reusing runAll anywhere else.
    if string.find(folder, 'reportlab' + os.sep + 'test') > -1: cleanup(folder)
    cleanup(outputfile(''))
    NI = []
    cleanOnly = '--clean' in sys.argv
    if not cleanOnly:
        testSuite = makeSuite(folder,nonImportable=NI,pattern=pattern+(not haveSRC and 'c' or ''))
        unittest.TextTestRunner().run(testSuite)
    if haveSRC: cleanup(folder,patterns=('*.pyc','*.pyo'))
    if not cleanOnly:
        if NI:
            sys.stderr.write('\n###################### the following tests could not be imported\n')
            for f,tb in NI:
                print 'file: "%s"\n%s\n' % (f,string.join(tb,''))
        printLocation()
        story.append(Spacer(0, 0.5*cm))

        w, h = drawWidth, drawHeight = 400, 100
        protoLabel = self._makeProtoLabel()
        protoLabel.setOrigin(drawWidth/2, drawHeight/2)
        protoLabel.width = 4*cm
        protoLabel.height = 1.5*cm
        protoLabel.textAnchor = 'start'
        protoLabel.fontName = 'Helvetica'
        protoLabel.fontSize = 10
        drawings = self._makeDrawings(protoLabel, text='Hello\nWorld!')
        for d in drawings:
            story.append(d)
            story.append(Spacer(0, 1*cm))

        story.append(PageBreak())

        path = outputfile('test_charts_textlabels.pdf')
        doc = MyDocTemplate(path)
        doc.multiBuild(story)


def makeSuite():
    return makeSuiteForClasses(LabelTestCase)


#noruntests
if __name__ == "__main__":
    unittest.TextTestRunner().run(makeSuite())
    printLocation()
示例#4
0
        from reportlab.lib.utils import FmtSelfDict

        class MixedIn(FmtSelfDict):
            def __init__(self):
                self.a = 'AA'
                self._b = '_BB'
                self.d = '(overridden)'

        obj = MixedIn()
        self.assertEqual('blah', obj._fmt('blah'))
        self.assertEqual('blah %', obj._fmt('blah %%'))
        self.assertRaises(ValueError, obj._fmt, 'blah %')
        self.assertEqual(
            'moon AA june_BB spoon %(a)sCC ni',
            obj._fmt('moon %(a)s june%(_b)s spoon %%(a)s%(c)s %(d)s',
                     c='CC',
                     C='boon',
                     d='ni'))
        self.assertRaises(AttributeError, obj._fmt,
                          '%(c)s')  # XXX bit weird, can this be changed?


def makeSuite():
    return makeSuiteForClasses(FmtTestCase)


#noruntests
if __name__ == "__main__":
    unittest.TextTestRunner().run(makeSuite())
    printLocation()