def test_format(self): """Tests if formatting works ok.""" id = indenter.Indent() id.incr() # test one liner with trailing newlines txt = """class foo:\n\n \n \n""" t1 = id.format(txt) self.assertEqual(t1, ' class foo:\n') # test one liner with no trailing newline. txt = """class foo:""" t1 = id.format(txt) self.assertEqual(t1, ' class foo:\n') # test multi-line text. txt = """print "hi!" if name == 'hi': print "hi, hi!" """ res = """ print "hi!"\n if name == 'hi':\n print "hi, hi!"\n""" self.assertEqual(id.format(txt), res) txt = """ class Foo: def __init__(self): pass def _get_a(self): return self._a""" res = """ class Foo: def __init__(self): pass def _get_a(self): return self._a""" + '\n' self.assertEqual(id.format(txt), res)
def test_class_doc(self): """Test if class docs are generated correctly.""" dm = indenter.VTKDocMassager() indent = indenter.Indent() out = cStringIO.StringIO() doc = "vtkLODProperty, vtkXMLDataReader, vtk3DSImporter\n"\ "SetRepresentationToWireframe, Write3DPropsAsRasterImage" dm.write_class_doc(doc, out, indent) out.seek(0) ret = out.read() correct = ''' """ LODProperty, XMLDataReader, ThreeDSImporter set_representation_to_wireframe, write3d_props_as_raster_image """\n''' #print ret #print correct self.assertEqual(ret, correct) # Test empty doc out = cStringIO.StringIO() doc = "" dm.write_class_doc(doc, out, indent) out.seek(0) ret = out.read() self.assertEqual(ret, ' """\n \n """\n')
def test_trait_doc(self): """Test if trait docs are generated correctly.""" dm = indenter.VTKDocMassager() indent = indenter.Indent() out = cStringIO.StringIO() doc = 'V.GetOutput(int) -> vtkStructuredPoints\n'\ 'C++: vtkStructuredPoints *GetOutput (int idx);\n'\ 'V.GetOutput() -> vtkStructuredPoints\n'\ 'C++: vtkStructuredPoints *GetOutput ();\n\n'\ 'vtkLODProperty, vtkXMLDataReader, vtk3DSImporter\n'\ 'SetRepresentationToWireframe, Write3DPropsAsRasterImage' dm.write_trait_doc(doc, out, indent) out.seek(0) ret = out.read() correct = ''' """ LODProperty, XMLDataReader, ThreeDSImporter set_representation_to_wireframe, write3d_props_as_raster_image """\n''' #print ret #print correct self.assertEqual(ret, correct) # Test empty doc. out = cStringIO.StringIO() doc = 'V.GetOutput(int) -> vtkStructuredPoints\n'\ 'C++: vtkStructuredPoints *GetOutput (int idx);\n'\ 'V.GetOutput() -> vtkStructuredPoints\n'\ 'C++: vtkStructuredPoints *GetOutput ();\n\n' dm.write_trait_doc(doc, out, indent) out.seek(0) ret = out.read() self.assertEqual(ret, ' """\n \n """\n')
def test_basic(self): """Simple tests for indenter.""" id = indenter.Indent() self.assertEqual(str(id), '') id.incr() self.assertEqual(str(id), ' ') id.incr() self.assertEqual(str(id), ' ') id.decr() self.assertEqual(str(id), ' ') id.decr() self.assertEqual(str(id), '') id.incr() id.incr() id.reset() self.assertEqual(str(id), '')
def test_method_doc(self): """Test if method docs are generated correctly.""" dm = indenter.VTKDocMassager() indent = indenter.Indent() out = cStringIO.StringIO() doc = 'V.GetOutput(int) -> vtkStructuredPoints\n'\ 'C++: vtkStructuredPoints *GetOutput (int idx);\n'\ 'V.GetOutput() -> vtkStructuredPoints\n'\ 'C++: vtkStructuredPoints *GetOutput ();\n\n'\ 'vtkLODProperty, vtkXMLDataReader, vtk3DSImporter\n'\ 'SetRepresentationToWireframe, Write3DPropsAsRasterImage' dm.write_method_doc(doc, out, indent) out.seek(0) ret = out.read() correct = ''' r""" V.get_output(int) -> StructuredPoints V.get_output() -> StructuredPoints LODProperty, XMLDataReader, ThreeDSImporter set_representation_to_wireframe, write3d_props_as_raster_image """\n''' self.assertEqual(ret, correct) # Test empty doc. out = cStringIO.StringIO() doc = 'V.GetOutput(int) -> vtkStructuredPoints\n'\ 'C++: vtkStructuredPoints *GetOutput (int idx);\n'\ 'V.GetOutput() -> vtkStructuredPoints\n'\ 'C++: vtkStructuredPoints *GetOutput ();\n\n' dm.write_method_doc(doc, out, indent) out.seek(0) ret = out.read() correct = ''' r""" V.get_output(int) -> StructuredPoints V.get_output() -> StructuredPoints """\n''' self.assertEqual(ret, correct) # Test doc with escape characters in it. xref: enthought/mayavi#1130 out = cStringIO.StringIO() doc = r""" GetProminentComponentValues(self, comp:int, values:vtkVariantArray, uncertainty:float=1.e-6, minimumProminence:float=1.e-3) -> None C++: virtual void GetProminentComponentValues(int comp, vtkVariantArray *values, double uncertainty=1.e-6, double minimumProminence=1.e-3) Populate the given vtkVariantArray with a set of distinct values. In practice, $N >= \frac{5}{P}\mathrm{ln}\left(\frac{1}{PU}\right)$ """.lstrip() dm.write_method_doc(doc, out, indent) ret = out.getvalue() correct = ''' r""" GetProminentComponentValues(self, comp:int, values:VariantArray, uncertainty:float=1.e-6, minimumProminence:float=1.e-3) -> None virtual void GetProminentComponentValues(int comp, VariantArray *values, double uncertainty=1.e-6, double minimumProminence=1.e-3) Populate the given VariantArray with a set of distinct values. In practice, $N >= \\frac{5}{P}\\mathrm{ln}\\left(\\frac{1}{PU}\\right)$ """\n''' self.assertEqual(ret, correct) # Check that ret is a valid representation of a string. This # will raise a DeprecationWarning if ret still contains invalid # escape sequences. self.assertIsInstance(eval(ret), str)