"""
Tests for the PlotFileSaver classes.

$Id$
"""
__version__='$Revision$'

import unittest

from topo.base.simulation import Simulation
from topo.base.cf import CFSheet, CFProjection
from topo.sheets.generatorsheet import GeneratorSheet

from topo.plotting.plotfilesaver import PlotGroupSaver,TemplatePlotGroupSaver,ConnectionFieldsPlotGroupSaver,CFProjectionPlotGroupSaver

from topo.plotting.plotgroup import PlotGroup

# CEBHACKALERT: seems like I'm testing analysis commands...i.e. I should have written
# a different test file...

PlotGroupSaver.filename_prefix="topo/tests/testplotfilesaver"

class TestPlotGroupSaver(unittest.TestCase):

    plotgroupsaver_class = PlotGroupSaver

    def setUp(self):
        self.sim = Simulation(register=True,name="PGS_test")
        self.sim['A'] = GeneratorSheet(nominal_density=4)
        self.sim['B'] = CFSheet(nominal_density=4)
        self.sim.connect('A','B',connection_type=CFProjection,name='Afferent')

    def save(self,name,**params):
        p = self.plotgroupsaver_class(name)
        p.generate_plotgroup(**params)
        p.plotgroup.make_plots(update=True)
        p.save_to_disk()


class TestTemplatePlotGroupSaver(TestPlotGroupSaver):
    plotgroupsaver_class = TemplatePlotGroupSaver

    def test_activity_saving(self):
        self.save('Activity')
        
    def test_orientation_preference_saving(self):
        self.save('Orientation Preference')


class TestConnectionFieldsPlotGroupSaver(TestPlotGroupSaver):
    plotgroupsaver_class = ConnectionFieldsPlotGroupSaver

    def test_cf_saving(self):
        self.save("Connection Fields",sheet=self.sim['B'])

        
class TestCFProjectionPlotGroupSaver(TestPlotGroupSaver):
    plotgroupsaver_class = CFProjectionPlotGroupSaver

    def test_cfprojection_saving(self):
        self.save('Projection',sheet=self.sim['B'],
                  projection=self.sim['B'].projections('Afferent'))




###########################################################

cases = [TestPlotGroupSaver,TestTemplatePlotGroupSaver,TestConnectionFieldsPlotGroupSaver,TestCFProjectionPlotGroupSaver]

suite = unittest.TestSuite()
suite.addTests([unittest.makeSuite(case) for case in cases])

if __name__ == '__main__':
    unittest.TextTestRunner(verbosity=2).run(suite)


@@ -85,16 +85,26 @@
 unittest
+%0Aimport os
 %0A%0Afrom t
@@ -184,24 +184,96 @@
 FProjection%0A
+from topo.base.parameterclasses import resolve_filename,normalize_path%0A%0A
 from topo.sh
@@ -676,16 +676,234 @@
 saver%22%0A%0A
+# remove old test output%0Atests_dir=normalize_path(%22topo/tests/%22)%0Afor f in os.listdir(tests_dir):%0A    if f.startswith(%22testplotfilesaverPGS_test%22) and f.endswith(%22.png%22):%0A        os.remove(os.path.join(tests_dir,f))%0A%0A%0A%0A
 class Te
@@ -1252,16 +1252,24 @@
 ferent')
+        
 %0A%0A    de
@@ -1633,102 +1633,715 @@
     
-%0A    def test_orientation_preference_saving(self):%0A        self.save('Orientation Preference')
+resolve_filename(%22topo/tests/testplotfilesaverPGS_test_000000.00_A_Activity.png%22)%0A        resolve_filename(%22topo/tests/testplotfilesaverPGS_test_000000.00_B_Activity.png%22)%0A%0A%0A%0A%0A%0A%0A        %0A    def test_orientation_preference_saving(self):%0A        self.save('Orientation Preference')%0A        resolve_filename(%22topo/tests/testplotfilesaverPGS_test_000000.00_B_Orientation_Preference.png%22)%0A        resolve_filename(%22topo/tests/testplotfilesaverPGS_test_000000.00_B_Orientation_PreferenceAndSelectivity.png%22)%0A        resolve_filename(%22topo/tests/testplotfilesaverPGS_test_000000.00_B_Orientation_Selectivity.png%22)%0A        resolve_filename(%22topo/tests/testplotfilesaverPGS_test_000000.00__Color_Key.png%22)%0A        %0A
 %0A%0A%0Ac
@@ -2548,16 +2548,113 @@
 im%5B'B'%5D)
+%0A        resolve_filename(%22topo/tests/testplotfilesaverPGS_test_000000.00_Afferent_(from_A).png%22)
 %0A%0A      
@@ -2929,16 +2929,106 @@
 rent'))%0A
+        resolve_filename(%22topo/tests/testplotfilesaverPGS_test_000000.00_B_Afferent.png%22)%0A
 %0A%0A%0A%0A####

Test that plots are actually written to disk.