Changeset 6184


Ignore:
Timestamp:
17/12/09 15:13:46 (10 years ago)
Author:
pnorton
Message:

Added some files to svn:ingore and wrote a couple of tests.

Location:
qesdi/linplot/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • qesdi/linplot/trunk/src/linplot.egg-info/PKG-INFO

    r6161 r6184  
    11Metadata-Version: 1.0 
    22Name: linplot 
    3 Version: 0.0.1-r6160 
     3Version: 0.0.1-r6161 
    44Summary: UNKNOWN 
    55Home-page: UNKNOWN 
  • qesdi/linplot/trunk/src/linplot/plot.py

    r6161 r6184  
    3535     
    3636    def draw(self, yData, xData, **kwargs): 
     37         
     38        kwargs.setdefault('label', 'Line #%s' % (len(self._ax.lines))) 
     39         
    3740        self._ax.add_line(matplotlib.lines.Line2D(yData, xData, **kwargs)) 
    3841          
    3942    def saveImage(self, outputFile): 
     43         
     44        if len(self._ax.lines) == 0: 
     45            raise Exception("Trying to create a plot with no lines.") 
     46         
    4047        self._scaleAxes() 
    4148        self._populateLegend() 
     
    7178    def _populateLegend(self): 
    7279         
     80        log.debug("self._ax.lines = %s" % (self._ax.lines,)) 
     81         
    7382        handles, labels = self._ax.get_legend_handles_labels() 
     83        log.debug("len(handles) = %s" % (len(handles),)) 
    7484 
    75         leg = self._legendAx.legend(handles, labels, ncol=3, 
     85        ncol = len(handles) if len(handles) < 3 else 3 
     86        log.debug("ncol = %s" % (ncol,)) 
     87 
     88        leg = self._legendAx.legend(handles, labels, ncol=ncol, 
    7689                                    loc=2, mode='expand', borderaxespad=0) 
    7790         
  • qesdi/linplot/trunk/test_outputs/draw

    • Property svn:ignore set to
      *
  • qesdi/linplot/trunk/tests/linplot_tests/unit/test_plot.py

    r6161 r6184  
    55''' 
    66 
     7import math 
    78from linplot import Plot 
    89import nose 
     10import nose.tools as nt 
    911import numpy 
     12from mock import Mock, patch 
    1013 
    1114 
     
    1518        self.xdata = numpy.arange(0, 4*math.pi, 0.1) 
    1619        self.ydata = [numpy.sin(x) for x in self.xdata] 
     20        self.plt = Plot() 
    1721     
    1822    def tearDown(self): 
    1923        pass 
    2024     
    21     def test_001_(self): 
    22         pass 
     25    @patch('linplot.utils.figureToImage') 
     26    def test_001_savesAnImage(self, mockFigToImage): 
     27        outputFile = "some_output/file" 
     28        self.plt.draw(self.xdata, self.ydata) 
     29        self.plt.saveImage(outputFile) 
     30 
     31        #check that the figure is set to the figureToImage function 
     32        nt.assert_equal(mockFigToImage.call_count, 1) 
     33        nt.assert_equal(mockFigToImage.call_args, ((self.plt._fig,),{}) ) 
    2334     
    24  
     35    def test_002_linesAreAdded(self): 
     36        # check the difference becuase there are some lines on  
     37        # the axes at the start 
     38        linesBefore = len(self.plt._ax.lines) 
     39        self.plt.draw(self.xdata, self.ydata) 
     40        linesAfter = len(self.plt._ax.lines) 
     41         
     42        nt.assert_equal(linesBefore + 1, linesAfter) 
    2543 
    2644if __name__ == '__main__': 
Note: See TracChangeset for help on using the changeset viewer.