Example #1
0
class TestData(unittest.TestCase):
    def setUp(self):
        self._tmpdir = tempfile.mkdtemp()
        if not os.path.exists(self._tmpdir):
            os.makedirs(self._tmpdir)
        self.R = Report('testfile',
                        'myreport',
                        'Alex Loew',
                        outdir=self._tmpdir + os.sep)

    def tearDown(self):
        pass

    def test_ReportInit(self):
        self.assertEqual(self.R.filename,
                         self._tmpdir + os.sep + 'testfile.tex')
        self.assertEqual(self.R.format, 'png')
        self.assertEqual(self.R.author, 'Alex Loew')

    def test_open_report(self):
        self.R.open()
        self.assertTrue(os.path.exists(self.R.filename))

    def test_open_report_MissingDirectory(self):
        self.R = Report('testfile',
                        'myreport',
                        'Alex Loew',
                        outdir=self._tmpdir + os.sep + 'nixdir')
        self.R.open()
        self.assertTrue(os.path.exists(self.R.filename))
        self.assertTrue(os.path.exists(self._tmpdir + os.sep + 'nixdir'))

    def test_report_features(self):
        if os.path.exists(self.R.filename):
            os.remove(self.R.filename)

        f = plt.figure()
        ax = f.add_subplot(111)
        ax.plot(np.random.random(200))

        self.R.open()
        self.R.section('This is a section')
        self.R.subsection('This is a subsection')
        self.R.subsubsection('This is a subsubsection')

        self.R.newpage()
        self.R.clearpage()

        self.R.barrier()
        self.R.open_table()
        self.R.close_table(caption='This is my caption')
        #self.input('filename_to_input.tex')

        self.R.newpage()
        self.R.figure(f, caption='My figure caption')

        self.R.close()
        self.R.compile()

        if os.path.exists(self.R.filename):
            os.remove(self.R.filename)
        if os.path.exists(self.R.filename[:-3] + '.pdf'):
            os.remove(self.R.filename[:-3] + '.pdf')

    def test_report_InvalidFigure(self):
        f = None
        r = self.R.figure(f, caption='My figure caption')
        self.assertEqual(r, None)

    #~ def test_report_CaptureFigures(self):
    #~ if os.path.exists(self.R.outdir + 'fig_00001.png'):
    #~ os.remove(self.R.outdir + 'fig_00001.png')
    #~ if os.path.exists(self.R.outdir + 'fig_00002.png'):
    #~ os.remove(self.R.outdir + 'fig_00002.png')
    #~ if os.path.exists(self.R.outdir + 'fig_00003.png'):
    #~ os.remove(self.R.outdir + 'fig_00003.png')
#~
#~ f1 = plt.figure()
#~ ax1 = f1.add_subplot(111)
#~ ax1.plot(np.random.random(100))
#~ f2 = plt.figure()
#~ ax2 = f2.add_subplot(111)
#~ ax2.plot(np.random.random(200))
#~ f3 = plt.figure()
#~ ax3 = f3.add_subplot(111)
#~ ax3.plot(np.random.random(300))
#~
#~ self.R.capture_figures()
#~
#~ self.assertTrue(os.path.exists(self.R.outdir + 'fig_00001.png'))
#~ self.assertTrue(os.path.exists(self.R.outdir + 'fig_00002.png'))
#~ self.assertTrue(os.path.exists(self.R.outdir + 'fig_00003.png'))

    def test_input(self):
        self.R.input('testname')
Example #2
0
class TestData(unittest.TestCase):
    def setUp(self):
        self._tmpdir = tempfile.mkdtemp()
        if not os.path.exists(self._tmpdir):
            os.makedirs(self._tmpdir)
        self.R = Report("testfile", "myreport", "Alex Loew", outdir=self._tmpdir + os.sep)

    def tearDown(self):
        pass

    def test_ReportInit(self):
        self.assertEqual(self.R.filename, self._tmpdir + os.sep + "testfile.tex")
        self.assertEqual(self.R.format, "png")
        self.assertEqual(self.R.author, "Alex Loew")

    def test_open_report(self):
        self.R.open()
        self.assertTrue(os.path.exists(self.R.filename))

    def test_open_report_MissingDirectory(self):
        self.R = Report("testfile", "myreport", "Alex Loew", outdir=self._tmpdir + os.sep + "nixdir")
        self.R.open()
        self.assertTrue(os.path.exists(self.R.filename))
        self.assertTrue(os.path.exists(self._tmpdir + os.sep + "nixdir"))

    def test_report_features(self):
        if os.path.exists(self.R.filename):
            os.remove(self.R.filename)

        f = plt.figure()
        ax = f.add_subplot(111)
        ax.plot(np.random.random(200))

        self.R.open()
        self.R.section("This is a section")
        self.R.subsection("This is a subsection")
        self.R.subsubsection("This is a subsubsection")

        self.R.newpage()
        self.R.clearpage()

        self.R.barrier()
        self.R.open_table()
        self.R.close_table(caption="This is my caption")
        # self.input('filename_to_input.tex')

        self.R.newpage()
        self.R.figure(f, caption="My figure caption")

        self.R.close()
        self.R.compile()

        if os.path.exists(self.R.filename):
            os.remove(self.R.filename)
        if os.path.exists(self.R.filename[:-3] + ".pdf"):
            os.remove(self.R.filename[:-3] + ".pdf")

    def test_report_InvalidFigure(self):
        f = None
        r = self.R.figure(f, caption="My figure caption")
        self.assertEqual(r, None)

    # ~ def test_report_CaptureFigures(self):
    # ~ if os.path.exists(self.R.outdir + 'fig_00001.png'):
    # ~ os.remove(self.R.outdir + 'fig_00001.png')
    # ~ if os.path.exists(self.R.outdir + 'fig_00002.png'):
    # ~ os.remove(self.R.outdir + 'fig_00002.png')
    # ~ if os.path.exists(self.R.outdir + 'fig_00003.png'):
    # ~ os.remove(self.R.outdir + 'fig_00003.png')
    # ~
    # ~ f1 = plt.figure()
    # ~ ax1 = f1.add_subplot(111)
    # ~ ax1.plot(np.random.random(100))
    # ~ f2 = plt.figure()
    # ~ ax2 = f2.add_subplot(111)
    # ~ ax2.plot(np.random.random(200))
    # ~ f3 = plt.figure()
    # ~ ax3 = f3.add_subplot(111)
    # ~ ax3.plot(np.random.random(300))
    # ~
    # ~ self.R.capture_figures()
    # ~
    # ~ self.assertTrue(os.path.exists(self.R.outdir + 'fig_00001.png'))
    # ~ self.assertTrue(os.path.exists(self.R.outdir + 'fig_00002.png'))
    # ~ self.assertTrue(os.path.exists(self.R.outdir + 'fig_00003.png'))

    def test_input(self):
        self.R.input("testname")
            os.remove(self.fname)
        self.handler = open(self.fname, 'w')

    def close(self):
        self.handler.close()

    def write(self, s):
        s += '\n'
        self.handler.write(s)


####################
# open report
####################
R = Report('merging_results', 'Merging', 'Alex')
R.open(landscape=False)

####################
# read all tables
####################
# read ALL latex tables
Tdata = []
for g in files:
    k = g.keys()[0]
    T = Table(k)
    T.read(rdir + g[k])
    Tdata.append(T)

# combine tables
# unique key list for all models
mkeys = []
            os.remove(self.fname)
        self.handler = open(self.fname, 'w')

    def close(self):
        self.handler.close()

    def write(self, s):
        s += '\n'
        self.handler.write(s)


####################
# open report
####################
R = Report('merging_results', 'Merging', 'Alex')
R.open(landscape=False)

####################
# read all tables
####################
# read ALL latex tables
Tdata = []
for g in files:
    k = g.keys()[0]
    T = Table(k)
    T.read(rdir + g[k])
    Tdata.append(T)

# combine tables
# unique key list for all models
mkeys = []