Ejemplo n.º 1
0
    def test_8getDefaultConverterName(self):
        """Test getDefaultConverterName()."""

        c1 = Converter1  # empty converter
        c4 = Converter4  # default converter
        c5 = Converter5
        c6 = Converter6  # second default
        c7 = Converter7

        ICRegistry._clear()

        self.assertNone(ICRegistry.getDefaultConverterName(), 'empty reg')
        self.failUnless(ICRegistry.register(c1))
        self.assertNone(ICRegistry.getDefaultConverterName(), 'empty reg 2nd')
        self.failUnless(ICRegistry.register(c5))
        self.assertNone(ICRegistry.getDefaultConverterName(), 'no default')
        self.failUnless(ICRegistry.register(c4))
        self.assertEqual(c4.name, ICRegistry.getDefaultConverterName(),
                         'default')
        self.assertRaises(RuntimeError, ICRegistry.register,
                          c6)  #second default
        self.assertNone(ICRegistry.getConverter(c6.name), 'get 2nd default')
        self.assertEqual(c4.name, ICRegistry.getDefaultConverterName(),
                         'default 2')
        self.failUnless(ICRegistry.register(c7))
        self.assertEqual(c4.name, ICRegistry.getDefaultConverterName(),
                         'default 3')
Ejemplo n.º 2
0
    def having_errors(self, whichTests='all'):
        """Test if we have errors.

        e.g. conflicts between diagramKind and converter
        """
        if whichTests == 'all':
            if self.current_version < self.version:
                return "Diagram is older than SVGrafZ-Product. \
                Please update the diagram as described in doc/update.txt"

            if self.current_version > self.version:
                return "Diagram is newer than SVGrafZ-Product. \
                Please update your SVGrafZ-Product to the latest version."

        diagramTypesOfConverter = ICRegistry.getConverter(
            self.convertername()).registration().keys()

        try:
            for diagramType in Registry.getKind(
                    self.graphname()).registration():
                if diagramType in diagramTypesOfConverter:
                    return False
        except RuntimeError:
            return "DiagramKind does not exist any more.\
            Please choose another."

        return "DiagramKind and Converter are incompatible. \
Ejemplo n.º 3
0
    def test_7getConverter(self):
        """Test getConverter(converterName)."""
        c1 = Converter1
        c4 = Converter4

        ICRegistry._clear()
        self.assertNone(ICRegistry.getConverter(c1.name), 'get c1 1st')
        self.assertNone(ICRegistry.getConverter(c4.name), 'get c4 1st')
        self.failUnless(ICRegistry.register(c1))
        self.assertNone(ICRegistry.getConverter(c1.name), 'get c1 2nd')
        self.assertNone(ICRegistry.getConverter(c4.name), 'get c4 2nd')
        self.failUnless(ICRegistry.register(c4))
        self.assertNone(ICRegistry.getConverter(c1.name), 'get c1 3rd')
        self.assertEqual(
            c4().__class__,
            ICRegistry.getConverter(c4.name).__class__,
            'get c4 3rd (%s != %s)' %
            (c4().__class__, ICRegistry.getConverter(c4.name).__class__))
Ejemplo n.º 4
0
 def viewInputConverterDesription(self):
     return self._list2dictlist(
         ICRegistry.getConverter(self.convertername()).description())
Ejemplo n.º 5
0
    def __call__(self, client=None, REQUEST={}):
        """Render the diagram."""
        graphClass = Registry.getKind(self.graphname())
        current = self.getPropertyValues()
        outputConverter, dummy = self._getOutputConverter()
        inputConverter = ICRegistry.getConverter(current['convertername'])
        errortext = legend = colnames = stylesheet = data = title = None

        if current['data'].getExpression() is None:
            errortext = "You did not enter a DataSource, so can't display anything."
        else:
            try:
                data = self.getValue(current['data'])
                try:
                    data = inputConverter.convert(data, current['fixcolumn'])
                except RuntimeError:
                    errortext = str(exc_info()[1])
                except (AttributeError, KeyError, CompilerError):
                    errortext = 'DataSource "%s" is not existing.' % (
                        current['data'])
            except RuntimeError:
                errortext = str(exc_info()[1])
        try:
            legend = self.getValue(current['legend'])
        except (AttributeError, KeyError, CompilerError):
            errortext = 'Legend "%s" is not existing.' % (current['legend'])

        if legend == 'converter':
            if IInputConverterWithLegend.isImplementedBy(inputConverter):
                legend = inputConverter.legend(
                )  # cause convert is already done
            else:
                errortext = "DataConverter '%s' can't be used with '%s'." % (
                    current['convertername'], 'string:converter')
        try:
            colnames = self.getValue(current['colnames'])
        except (AttributeError, KeyError, CompilerError):
            errortext = 'ColumnNames "%s" do not exist.' % (
                current['colnames'])

        if current['stylesheet']:
            try:
                stylesheet = getattr(self, current['stylesheet'])
                stylesheet = outputConverter.getStyleSheetURL(stylesheet)
            except AttributeError:
                errortext = 'Stylesheet "%s" is not existing.' % (
                    current['stylesheet'])
        try:
            title = self.getValue(current['taltitle'])
        except (AttributeError, KeyError, CompilerError, RuntimeError):
            errortext = '"Title with TALES" has Errors.'
        if title is None:
            title = current['title'] or ''

        otherParams = {
            'gridlines': current['gridlines'],
            'height': current['height'],
            'width': current['width'],
            'intcaption': current['intcaption'],
            'fillgaps': current['fillgaps'],
        }
        graph = graphClass(data=data,
                           legend=legend,
                           colnames=colnames,
                           title=title,
                           stylesheet=stylesheet,
                           otherParams=otherParams,
                           errortext=errortext)
        graph.setSpecialAttrib(current['specialattrib'])
        if REQUEST.RESPONSE:
            outputConverter.setHTTPHeaders(
                REQUEST.RESPONSE,
                title.replace(' ', '_') or 'unnamed')
        outputConverter.setSourceData(graph.compute().encode('UTF-8'))
        if not outputConverter.convert():
            return outputConverter.getErrorResult()
        else:
            return outputConverter.getResultData()