<commit_before>"""Tests for reportlab.lib.utils
"""
import os
import reportlab
from reportlab.test import unittest
from reportlab.test.utils import makeSuiteForClasses
from reportlab.lib import colors
from reportlab.lib.utils import recursiveImport, \
                                 recursiveGetAttr, \
                                recursiveSetAttr



class ImporterTestCase(unittest.TestCase):
    "Test import utilities"

    def test1(self):
        "try stuff known to be in the path"
        m1 = recursiveImport('reportlab.pdfgen.canvas')
        import reportlab.pdfgen.canvas
        assert m1 == reportlab.pdfgen.canvas

    def test2(self):
        "try under a directory NOT on the path"
        D = os.path.join(os.path.dirname(reportlab.__file__), 'tools','pythonpoint')
        fn = os.path.join(D,'stdparser.py')
        if os.path.isfile(fn) or os.path.isfile(fn+'c') or os.path.isfile(fn+'o'):
            m1 = recursiveImport('stdparser', baseDir=D)
        
    def test3(self):
        "ensure CWD is on the path"
        rlDir = os.path.dirname(reportlab.__file__)
        testDir = os.path.join(rlDir, 'test')
        cwd = os.getcwd()
        os.chdir(testDir)
        m1 = recursiveImport('test_lib_colors')

    def test4(self):
        "ensure noCWD removes current dir from path"
        rlDir = os.path.dirname(reportlab.__file__)
        testDir = os.path.join(rlDir, 'test')
        cwd = os.getcwd()
        os.chdir(testDir)
        self.assertRaises(ImportError,
                          recursiveImport,
                          'test_lib_colors',
                          noCWD=1)

    def test5(self):
        "recursive attribute setting/getting on modules"
        import reportlab.lib.units
        inch = recursiveGetAttr(reportlab, 'lib.units.inch')
        assert inch == 72

        recursiveSetAttr(reportlab, 'lib.units.cubit', 18*inch)        
        cubit = recursiveGetAttr(reportlab, 'lib.units.cubit')
        assert cubit == 18*inch

    def test6(self):
        "recursive attribute setting/getting on drawings"
        from reportlab.graphics.charts.barcharts import sampleH1
        drawing = sampleH1()
        recursiveSetAttr(drawing, 'barchart.valueAxis.valueMax', 72)<commit_msg>Fix already imprted test module<commit_after>"""Tests for reportlab.lib.utils
"""
import os
import reportlab
from reportlab.test import unittest
from reportlab.test.utils import makeSuiteForClasses
from reportlab.lib import colors
from reportlab.lib.utils import recursiveImport, \
                                 recursiveGetAttr, \
                                recursiveSetAttr



class ImporterTestCase(unittest.TestCase):
    "Test import utilities"

    def test1(self):
        "try stuff known to be in the path"
        m1 = recursiveImport('reportlab.pdfgen.canvas')
        import reportlab.pdfgen.canvas
        assert m1 == reportlab.pdfgen.canvas

    def test2(self):
        "try under a directory NOT on the path"
        D = os.path.join(os.path.dirname(reportlab.__file__), 'tools','pythonpoint')
        fn = os.path.join(D,'stdparser.py')
        if os.path.isfile(fn) or os.path.isfile(fn+'c') or os.path.isfile(fn+'o'):
            m1 = recursiveImport('stdparser', baseDir=D)
        
    def test3(self):
        "ensure CWD is on the path"
        rlDir = os.path.dirname(reportlab.__file__)
        testDir = os.path.join(rlDir, 'test')
        cwd = os.getcwd()
        os.chdir(testDir)
        m1 = recursiveImport('test_lib_colors')

    def test4(self):
        "ensure noCWD removes current dir from path"
        rlDir = os.path.dirname(reportlab.__file__)
        testDir = os.path.join(rlDir, 'test')
        cwd = os.getcwd()
        os.chdir(testDir)
        import sys
        try:
            del sys.modules['test_lib_colors']
        except KeyError:
            pass
        self.assertRaises(ImportError,
                          recursiveImport,
                          'test_lib_colors',
                          noCWD=1)

    def test5(self):
        "recursive attribute setting/getting on modules"
        import reportlab.lib.units
        inch = recursiveGetAttr(reportlab, 'lib.units.inch')
        assert inch == 72

        recursiveSetAttr(reportlab, 'lib.units.cubit', 18*inch)        
        cubit = recursiveGetAttr(reportlab, 'lib.units.cubit')
        assert cubit == 18*inch

    def test6(self):
        "recursive attribute setting/getting on drawings"
        from reportlab.graphics.charts.barcharts import sampleH1
        drawing = sampleH1()
        recursiveSetAttr(drawing, 'barchart.valueAxis.valueMax', 72)
{'fraction_non_alphanumeric': 0.09864018994172243, 'fraction_numerical': 0.009065400388517159, 'mean_word_length': 2.2270194986072425, 'pattern_counts': {'":': 0, '<': 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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5428048', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1355, 'n_words': 311}