TestPyutPreferences.py :  » UML » Python-UML-Tool » pyut-1.4.0 » src » tests » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » UML » Python UML Tool 
Python UML Tool » pyut 1.4.0 » src » tests » TestPyutPreferences.py
#!/usr/bin/env python

__version__ = "$Revision: 1.1.1.1 $"
__author__ = "EI6, eivd, Group Dutoit - Roux"
__date__ = "2002-05-22"

import sys
if ".." not in sys.path:
    sys.path.append("..") # access to the classes to test
import unittest

from PyutPreferences import PyutPreferences,PREFS_FILENAME
import os

class TestPyutPreferences(unittest.TestCase):
    """
    @author Laurent Burgbacher <lb@alawa.ch>
    """
    def emptyPrefs(self):
        """
        Empty the preferences.

        Do this by removing the prefs file and reinit the prefs
        (``prefs.init``).
        """
        if os.path.exists(PREFS_FILENAME):
            os.remove(PREFS_FILENAME)
        self.prefs.init()
        # test that it's empty
        try:
            self.failUnless(self.prefs[self.items.keys()[0]] is None)
        except:
            self.fail("Should not raise an exception")

    #>------------------------------------------------------------------------

    def setUp(self):
        """
        Remove any existing prefs file.

        Instantiate a prefs (Singleton class) and fill it.
        """
        self.items = {
            "test_int" : 12,
            "test_double" : 12.12,
            "test_string" : "salut",
            "test_tuple" : ("salut", "les", "amis"),
            "test_list" : ["comment", "allez", "vous"],
        }
        self.prefs = PyutPreferences()
        self.emptyPrefs() # empty the prefs
        # fill the prefs
        for item, value in self.items.items():
            self.prefs[item] = value

    #>------------------------------------------------------------------------

    def testValues(self):
        """
        Test that the prefs contain the good values.
        """
        for item, value in self.items.items():
            found = self.prefs[item]
            self.failUnless(found == str(value),
                "Wrong value for %s. Want %s, got %s" % (item, value, found))

    #>------------------------------------------------------------------------

    def testSpaceInName(self):
        """
        Test what happened with a space in the name of a pref.
        """
        try:
            self.prefs["salut les amis"] = 3
        except TypeError:
            pass # that's OK
        else:
            self.fail("A name without spaces has not raised an exception")

    #>------------------------------------------------------------------------

    def testLoadSave(self):
        """
        Test that load and save work correctly.
        """
        # now, prefs is already loaded, add some values that are automatically
        # saved
        self.prefs["new_pref"] = 10
        self.prefs.init() # reinit the object (that's the only way since it's
                          # a singleton
        self.failUnless(self.prefs["new_pref"] == "10", "Value doesn't exist")

    #>------------------------------------------------------------------------

    def testGetUnknowPref(self):
        """
        What happens with an unknown pref.
        """
        try:
            self.failUnless(self.prefs["unknown"] is None)
        except:
            self.fail("Should not raise an exception")

    #>------------------------------------------------------------------------

    def testGetUnknownPrefWhenEmpty(self):
        """
        What happens with an unknown section.

        All is now in `emptyPrefs`.
        """
        self.emptyPrefs()

    #>------------------------------------------------------------------------

    def testLastOpenedFiles(self):
        """
        Test the last opened files management.
        """
        files = [
            "un", "deux", "trois", "quatre", "cinq", "six"
        ]
        self.prefs.setNbLOF(len(files) - 1)
        self.prefs.init() # reload prefs
        self.failUnless(self.prefs.getNbLOF() == len(files) - 1, "wrong nbLOF")
        for file in files:
            self.prefs.addNewLastOpenedFilesEntry(file)
        self.prefs.init()
        files.reverse() # because it's a last in first out
        files.pop() # remove last one which should have been dropped
        for i in range(len(files) - 1):
            self.failUnless(self.prefs.getLastOpenedFilesList()[i] == files[i],
                "wrong file name")

    #>------------------------------------------------------------------------


def suite():
    """You need to change the name of the test class here also."""
    return unittest.makeSuite(TestPyutPreferences)

def main():
    unittest.TextTestRunner().run(suite())

if __name__ == "__main__": main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.