Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: fde2e1c7dc
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 100 lines (76 sloc) 3.612 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
import os, sys, unittest
from unittest import TestCase
import kiss
from kiss import Slides, Slide

# run with "python testsuite.py"

in_fname = "example.mdwn"

class SlidesTest (TestCase):
   def setUp (self):
      self.slides = Slides(in_fname, template=kiss.get_template("template.html"),
                           opt={'title_h1':True})
   def tearDown (self): pass
        
   def test_init (self):

      """ Test Slides initialization. """

      self.failUnless(self.slides.template != None)

      unloaded_slides = Slides(template=kiss.get_template("template.html"), opt={'test':True})
      self.failUnless(unloaded_slides.slides == [])
      self.failUnless(unloaded_slides.opt['test'])
      
   def test_load (self):

      """ Test loading of example file. """

      self.failUnless(os.path.exists(in_fname))
      self.failUnless(self.slides.fname == in_fname)
      self.failUnless(self.slides.count == 14, "There are 9 slides in the example deck (and one universal slide).")
      self.failUnless(len(self.slides.slides) == 15, "There are 9 slides in the example deck (and one universal slide).")

   def test_load_defaults(self):
      """ Test loading of defaults from example file.

For demonstration to the end user, the example file explicitly
sets values that match the defaults. This is convenient because
we can test the loaded values against the defaults. If they don't
match, either the load went wrong or the example file deviates (as
it does by design for bg_image, for example.)
"""

      u = self.slides.slides[0].fields
      d = kiss.defaults
      self.failUnless(u['bg_color'] == d['bg_color'])
      self.failUnless(u['text_color'] == d['text_color'])
      self.failUnless(u['font_family'] == d['font_family'])
      self.failUnless(u['font_size'] == d['font_size'])
      self.failUnless(u['font_style'] == d['font_style'])
      self.failUnless(u['font_weight'] == d['font_weight'])
      self.failUnless(u['opacity'] == d['opacity'])
      self.failUnless(u['text_bg'] == d['text_bg'])
      self.failUnless(u['hpos'] == d['hpos'])
      self.failUnless(u['vpos'] == d['vpos'])
      self.failUnless(u['halign'] == d['halign'])
      self.failUnless(u['duration'] == d['duration'])
      self.failUnless(u['bg_image'] == 'images/example.png')
      self.failUnless(u['bg_height'] == d['bg_height'])
      self.failUnless(u['bg_width'] == d['bg_width'])
      self.failUnless(u['bg_x'] == d['bg_x'])
      self.failUnless(u['bg_y'] == d['bg_y'])
      self.failUnless(u['title'] == "KISS Demo")

   def test_unicode(self):
      """ Test that we load unicode input file properly. """

      ## Unicode strings inherit from basestring but not str
      f = self.slides.slides[1].fields
      self.failUnless(isinstance(f['content'], basestring))
      self.failIf(isinstance(f['content'], str), "Content isn't a str (Unicode strings don't inherit from str).")

   def test_comments(self):
      """ Test handling of comment lines (they start with ;) in input file. """

      for s in self.slides.slides:
         for line in s.fields['content'].split("\n"):
            self.failIf(line.startswith(';'), "No comments made it in to content.")

   def test_render (self):
      """ Test rendering of Slides. """
      self.slides.render()
      pass

 
def suite():

   suite1= unittest.TestLoader().loadTestsFromTestCase(SlidesTest)
   suite = unittest.TestSuite([suite1])
   return suite

def main():
   runner = unittest.TextTestRunner()
   test_suite = suite()
   runner.run (test_suite)

if __name__ == '__main__':
   main()
Something went wrong with that request. Please try again.