CategorizableTest.py :  » Project-Management » Task-Coach » TaskCoach-1.0.3 » tests » unittests » domainTests » 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 » Project Management » Task Coach 
Task Coach » TaskCoach 1.0.3 » tests » unittests » domainTests » CategorizableTest.py
'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2010 Frank Niessink <frank@niessink.com>

Task Coach is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Task Coach is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

import test, wx
from taskcoachlib import patterns
from taskcoachlib.domain import category,categorizable



class CategorizableCompositeObjectTest(test.TestCase):
    def setUp(self):
        self.categorizable = categorizable.CategorizableCompositeObject(subject='categorizable')
        self.category = category.Category('category')
        
    categoryAddedEventType = categorizable.CategorizableCompositeObject.categoryAddedEventType()
    categoryRemovedEventType = categorizable.CategorizableCompositeObject.categoryRemovedEventType()
    totalCategoryAddedEventType = categorizable.CategorizableCompositeObject.totalCategoryAddedEventType()
    totalCategoryRemovedEventType = categorizable.CategorizableCompositeObject.totalCategoryRemovedEventType()
    categorySubjectChangedEventType = categorizable.CategorizableCompositeObject.categorySubjectChangedEventType()
    totalCategorySubjectChangedEventType = categorizable.CategorizableCompositeObject.totalCategorySubjectChangedEventType()
    foregroundColorChangedEventType = categorizable.CategorizableCompositeObject.foregroundColorChangedEventType()
    backgroundColorChangedEventType = categorizable.CategorizableCompositeObject.backgroundColorChangedEventType()
    fontChangedEventType = categorizable.CategorizableCompositeObject.fontChangedEventType()
    iconChangedEventType = categorizable.CategorizableCompositeObject.iconChangedEventType()
        
    def testCategorizableDoesNotBelongToAnyCategoryByDefault(self):
        for recursive in False, True:
            self.failIf(self.categorizable.categories(recursive=recursive))

    def testCategorizableHasNoForegroundColorByDefault(self):
        self.assertEqual(None, self.categorizable.foregroundColor())
    
    def testCategorizableHasNoBackgroundColorByDefault(self):
        self.assertEqual(None, self.categorizable.backgroundColor())

    def testCategorizableHasNoFontByDefault(self):
        self.assertEqual(None, self.categorizable.font())
        
    def testAddCategory(self):
        self.categorizable.addCategory(self.category)
        self.assertEqual(set([self.category]), self.categorizable.categories())

    def testAddCategoryNotification(self):
        self.registerObserver(self.categoryAddedEventType)
        self.categorizable.addCategory(self.category)
        self.assertEqual([patterns.Event( \
            self.categoryAddedEventType, self.categorizable, self.category)], 
            self.events)    
        
    def testAddSecondCategory(self):
        self.categorizable.addCategory(self.category)
        cat2 = category.Category('category 2')
        self.categorizable.addCategory(cat2)
        self.assertEqual(set([self.category, cat2]), 
            self.categorizable.categories())
        
    def testAddSameCategoryTwice(self):
        self.categorizable.addCategory(self.category)
        self.categorizable.addCategory(self.category)
        self.assertEqual(set([self.category]), self.categorizable.categories())
        
    def testAddSameCategoryTwiceCausesNoNotification(self):
        self.categorizable.addCategory(self.category)
        self.registerObserver(self.categoryAddedEventType)
        self.categorizable.addCategory(self.category)
        self.failIf(self.events)
    
    def testAddCategoryViaConstructor(self):
        categorizableObject = categorizable.CategorizableCompositeObject(categories=[self.category])
        self.assertEqual(set([self.category]), categorizableObject.categories())
        
    def testAddCategoriesViaConstructor(self):
        anotherCategory = category.Category('Another category')
        categories = [self.category, anotherCategory]
        categorizableObject = categorizable.CategorizableCompositeObject(categories= \
            categories)
        self.assertEqual(set(categories), categorizableObject.categories())
        
    def testAddCategoryDoesNotAddCategorizableToCategory(self):
        self.categorizable.addCategory(self.category)
        self.assertEqual(set([]), self.category.categorizables())
        
    def testAddParentToCategory(self):
        self.registerObserver(self.totalCategoryAddedEventType)
        child = categorizable.CategorizableCompositeObject(subject='child')
        self.categorizable.addChild(child)
        child.setParent(self.categorizable)
        cat = category.Category(subject='Parent category')
        self.categorizable.addCategory(cat)
        self.assertEqual([patterns.Event(self.totalCategoryAddedEventType, 
            child, cat)], self.events)
        
    def testRemoveCategory(self):
        self.categorizable.addCategory(self.category)
        self.categorizable.removeCategory(self.category)
        self.assertEqual(set(), self.categorizable.categories())
        
    def testRemoveCategoryNotification(self):
        self.categorizable.addCategory(self.category)
        self.registerObserver(self.categoryRemovedEventType)
        self.categorizable.removeCategory(self.category)
        self.assertEqual(self.category, self.events[0].value())

    def testRemoveCategoryTwice(self):
        self.categorizable.addCategory(self.category)
        self.categorizable.removeCategory(self.category)
        self.categorizable.removeCategory(self.category)
        self.assertEqual(set(), self.categorizable.categories())

    def testRemoveCategoryTwiceNotification(self):
        self.categorizable.addCategory(self.category)
        self.registerObserver(self.categoryRemovedEventType)
        self.categorizable.removeCategory(self.category)
        self.categorizable.removeCategory(self.category)
        self.assertEqual(1, len(self.events))
        
    def testCategorySubjectChanged(self):
        self.registerObserver(self.categorySubjectChangedEventType)
        self.registerObserver(self.totalCategorySubjectChangedEventType)
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.category.setSubject('New subject')
        expectedEvent = patterns.Event()
        expectedEvent.addSource(self.categorizable, 'New subject', type=self.categorySubjectChangedEventType)
        expectedEvent.addSource(self.categorizable, 'New subject', type=self.totalCategorySubjectChangedEventType)
        self.assertEqual([expectedEvent], self.events) 

    def testCategorySubjectChanged_NotifySubItemsToo(self):
        self.registerObserver(self.categorySubjectChangedEventType)
        self.registerObserver(self.totalCategorySubjectChangedEventType)
        childCategorizable = categorizable.CategorizableCompositeObject(subject='Child categorizable')
        self.categorizable.addChild(childCategorizable)
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.category.setSubject('New subject')
        expectedEvent = patterns.Event()
        expectedEvent.addSource(self.categorizable, 'New subject', type=self.categorySubjectChangedEventType)
        expectedEvent.addSource(self.categorizable, 'New subject', type=self.totalCategorySubjectChangedEventType)
        expectedEvent.addSource(childCategorizable, 'New subject', type=self.totalCategorySubjectChangedEventType)
        self.assertEqual([expectedEvent], self.events) 

    def testForegroundColor(self):
        self.categorizable.addCategory(self.category)
        self.category.setForegroundColor(wx.RED)
        self.assertEqual(wx.RED, self.categorizable.foregroundColor())

    def testBackgroundColor(self):
        self.categorizable.addCategory(self.category)
        self.category.setBackgroundColor(wx.RED)
        self.assertEqual(wx.RED, self.categorizable.backgroundColor())
        
    def testFont(self):
        self.categorizable.addCategory(self.category)
        self.category.setFont(wx.SWISS_FONT)
        self.assertEqual(wx.SWISS_FONT, self.categorizable.font(recursive=True))

    def testCategorizableOwnForegroundColorOverridesCategoryForegroundColor(self):
        self.categorizable.addCategory(self.category)
        self.category.setForegroundColor(wx.RED)
        self.categorizable.setForegroundColor(wx.GREEN)
        self.assertEqual(wx.GREEN, self.categorizable.foregroundColor())

    def testCategorizableOwnBackgroundColorOverridesCategoryBackgroundColor(self):
        self.categorizable.addCategory(self.category)
        self.category.setBackgroundColor(wx.RED)
        self.categorizable.setBackgroundColor(wx.GREEN)
        self.assertEqual(wx.GREEN, self.categorizable.backgroundColor())

    def testCategorizableOwnFontOverridesCategoryFont(self):
        self.categorizable.addCategory(self.category)
        self.category.setFont(wx.SWISS_FONT)
        self.categorizable.setFont(wx.NORMAL_FONT)
        self.assertEqual(wx.NORMAL_FONT, self.categorizable.font())
        
    def testForegroundColorWithTupleColor(self):
        self.categorizable.addCategory(self.category)
        self.category.setForegroundColor((255, 0, 0, 255))
        self.assertEqual(wx.RED, self.categorizable.foregroundColor())
        
    def testBackgroundColorWithTupleColor(self):
        self.categorizable.addCategory(self.category)
        self.category.setBackgroundColor((255, 0, 0, 255))
        self.assertEqual(wx.RED, self.categorizable.backgroundColor())

    def testSubItemUsesParentForegroundColor(self):
        self.categorizable.addCategory(self.category)
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        child.setParent(self.categorizable)
        self.category.setForegroundColor(wx.RED)
        self.assertEqual(wx.RED, child.foregroundColor())
    
    def testSubItemUsesParentBackgroundColor(self):
        self.categorizable.addCategory(self.category)
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        child.setParent(self.categorizable)
        self.category.setBackgroundColor(wx.RED)
        self.assertEqual(wx.RED, child.backgroundColor())
        
    def testSubItemUsesParentFont(self):
        self.categorizable.addCategory(self.category)
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        child.setParent(self.categorizable)
        self.category.setFont(wx.SWISS_FONT)
        self.assertEqual(wx.SWISS_FONT, child.font(recursive=True))

    def testSubItemDoesNotUseParentForegroundColorWhenItHasItsOwnForegroundColor(self):
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        child.setParent(self.categorizable)
        child.addCategory(self.category)
        self.categorizable.setForegroundColor(wx.RED)
        self.category.setForegroundColor(wx.BLUE)
        self.assertEqual(wx.BLUE, child.foregroundColor())
        
    def testSubItemDoesNotUseParentBackgroundColorWhenItHasItsOwnBackgroundColor(self):
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        child.setParent(self.categorizable)
        child.addCategory(self.category)
        self.categorizable.setBackgroundColor(wx.RED)
        self.category.setBackgroundColor(wx.BLUE)
        self.assertEqual(wx.BLUE, child.backgroundColor())

    def testSubItemDoesNotUseParentFontWhenItHasItsOwnFont(self):
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        child.setParent(self.categorizable)
        child.addCategory(self.category)
        self.categorizable.setFont(wx.Font(10, wx.FONTFAMILY_SWISS, 
            wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
        categoryFont = wx.Font(11, wx.FONTFAMILY_ROMAN, 
            wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL)
        self.category.setFont(categoryFont)
        self.assertEqual(categoryFont, child.font(recursive=True))

    def testForegroundColorChanged(self):
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.registerObserver(self.foregroundColorChangedEventType)
        self.category.setForegroundColor(wx.RED)
        self.assertEqual(1, len(self.events))
    
    def testBackgroundColorChanged(self):
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.registerObserver(self.backgroundColorChangedEventType)
        self.category.setBackgroundColor(wx.RED)
        self.assertEqual(1, len(self.events))
        
    def testFontChanged(self):
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.registerObserver(self.fontChangedEventType)
        self.category.setFont(wx.SWISS_FONT)
        self.assertEqual(1, len(self.events))

    def testIconChanged(self):
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.registerObserver(self.iconChangedEventType)
        self.category.setIcon('icon')
        self.assertEqual(1, len(self.events))

    def testForegroundColorChanged_NotifySubItemsToo(self):
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        self.registerObserver(self.foregroundColorChangedEventType, eventSource=child)
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.category.setForegroundColor(wx.RED)
        self.assertEqual(1, len(self.events))

    def testBackgroundColorChanged_NotifySubItemsToo(self):
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        self.registerObserver(self.backgroundColorChangedEventType, 
                              eventSource=child)
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.category.setBackgroundColor(wx.RED)
        self.assertEqual(1, len(self.events))

    def testFontChanged_NotifySubItemsToo(self):
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        self.registerObserver(self.fontChangedEventType, eventSource=child)
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.category.setFont(wx.SWISS_FONT)
        self.assertEqual(1, len(self.events))

    def testIconChanged_NotifySubItemsToo(self):
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        self.registerObserver(self.iconChangedEventType, eventSource=child)
        self.categorizable.addCategory(self.category)
        self.category.addCategorizable(self.categorizable)
        self.category.setIcon('icon')
        self.assertEqual(1, len(self.events))

    def testCategorizableDoesNotNotifyWhenItHasItsOwnForegroundColor(self):
        self.categorizable.addCategory(self.category)
        self.categorizable.setForegroundColor(wx.RED)
        self.registerObserver(self.categorizable.foregroundColorChangedEventType())
        self.category.setForegroundColor(wx.GREEN)
        self.assertEqual(0, len(self.events))
                
    def testCategorizableDoesNotNotifyWhenItHasItsOwnBackgroundColor(self):
        self.categorizable.addCategory(self.category)
        self.categorizable.setBackgroundColor(wx.RED)
        self.registerObserver(self.categorizable.backgroundColorChangedEventType())
        self.category.setBackgroundColor(wx.GREEN)
        self.assertEqual(0, len(self.events))

    def testCategorizableDoesNotNotifyWhenItHasItsOwnFont(self):
        self.categorizable.addCategory(self.category)
        self.categorizable.setFont(wx.SWISS_FONT)
        self.registerObserver(self.categorizable.fontChangedEventType())
        self.category.setFont(wx.NORMAL_FONT)
        self.assertEqual(0, len(self.events))

    def testCategorizableDoesNotNotifyWhenItHasItsOwnIcon(self):
        self.categorizable.addCategory(self.category)
        self.categorizable.setIcon('icon')
        self.registerObserver(self.categorizable.iconChangedEventType())
        self.category.setIcon('another icon')
        self.assertEqual(0, len(self.events))

    def testParentForegroundColorChanged(self):
        self.registerObserver(self.foregroundColorChangedEventType)
        subCategory = category.Category('Subcategory')
        self.category.addChild(subCategory)
        subCategory.setParent(self.category)
        self.categorizable.addCategory(subCategory)
        subCategory.addCategorizable(self.categorizable)
        self.category.setForegroundColor(wx.RED)
        self.assertEqual(1, len(self.events))
        
    def testParentBackgroundColorChanged(self):
        self.registerObserver(self.backgroundColorChangedEventType)
        subCategory = category.Category('Subcategory')
        self.category.addChild(subCategory)
        subCategory.setParent(self.category)
        self.categorizable.addCategory(subCategory)
        subCategory.addCategorizable(self.categorizable)
        self.category.setBackgroundColor(wx.RED)
        self.assertEqual(1, len(self.events))

    def testParentFontChanged(self):
        self.registerObserver(self.fontChangedEventType)
        subCategory = category.Category('Subcategory')
        self.category.addChild(subCategory)
        subCategory.setParent(self.category)
        self.categorizable.addCategory(subCategory)
        subCategory.addCategorizable(self.categorizable)
        self.category.setFont(wx.SWISS_FONT)
        self.assertEqual(1, len(self.events))

    def testParentIconChanged(self):
        self.registerObserver(self.iconChangedEventType)
        subCategory = category.Category('Subcategory')
        self.category.addChild(subCategory)
        subCategory.setParent(self.category)
        self.categorizable.addCategory(subCategory)
        subCategory.addCategorizable(self.categorizable)
        self.category.setIcon('icon')
        self.assertEqual(1, len(self.events))
        
    def testAddCategoryWithForegroundColor(self):
        self.registerObserver(self.foregroundColorChangedEventType)
        newCategory = category.Category('New category')
        newCategory.setForegroundColor(wx.RED)
        self.categorizable.addCategory(newCategory)
        self.assertEqual(1, len(self.events))
        
    def testAddCategoryWithBackgroundColor(self):
        self.registerObserver(self.backgroundColorChangedEventType)
        newCategory = category.Category('New category')
        newCategory.setBackgroundColor(wx.RED)
        self.categorizable.addCategory(newCategory)
        self.assertEqual(1, len(self.events))

    def testAddCategoryWithFont(self):
        self.registerObserver(self.fontChangedEventType)
        newCategory = category.Category('New category')
        newCategory.setFont(wx.SWISS_FONT)
        self.categorizable.addCategory(newCategory)
        self.assertEqual(1, len(self.events))

    def testAddCategoryWithIcon(self):
        self.registerObserver(self.iconChangedEventType)
        newCategory = category.Category('New category')
        newCategory.setIcon('icon')
        self.categorizable.addCategory(newCategory)
        self.assertEqual(1, len(self.events))

    def testAddCategoryWithParentWithForegroundColor(self):
        self.registerObserver(self.foregroundColorChangedEventType)
        parentCategory = category.Category('Parent')
        parentCategory.setForegroundColor(wx.RED)
        childCategory = category.Category('Child')
        parentCategory.addChild(childCategory)
        childCategory.setParent(parentCategory)
        self.categorizable.addCategory(childCategory)
        self.assertEqual(1, len(self.events))
        
    def testAddCategoryWithParentWithBackgroundColor(self):
        self.registerObserver(self.backgroundColorChangedEventType)
        parentCategory = category.Category('Parent')
        parentCategory.setBackgroundColor(wx.RED)
        childCategory = category.Category('Child')
        parentCategory.addChild(childCategory)
        childCategory.setParent(parentCategory)
        self.categorizable.addCategory(childCategory)
        self.assertEqual(1, len(self.events))

    def testAddCategoryWithParentWithFont(self):
        self.registerObserver(self.fontChangedEventType)
        parentCategory = category.Category('Parent')
        parentCategory.setFont(wx.SWISS_FONT)
        childCategory = category.Category('Child')
        parentCategory.addChild(childCategory)
        childCategory.setParent(parentCategory)
        self.categorizable.addCategory(childCategory)
        self.assertEqual(1, len(self.events))

    def testAddCategoryWithParentWithIcon(self):
        self.registerObserver(self.iconChangedEventType)
        parentCategory = category.Category('Parent')
        parentCategory.setIcon('icon')
        childCategory = category.Category('Child')
        parentCategory.addChild(childCategory)
        childCategory.setParent(parentCategory)
        self.categorizable.addCategory(childCategory)
        self.assertEqual(1, len(self.events))

    def testRemoveCategoryWithForegroundColor(self):
        self.categorizable.addCategory(self.category)
        self.category.setForegroundColor(wx.RED)
        self.registerObserver(self.foregroundColorChangedEventType)
        self.categorizable.removeCategory(self.category)
        self.assertEqual(1, len(self.events))
        
    def testRemoveCategoryWithBackgroundColor(self):
        self.categorizable.addCategory(self.category)
        self.category.setBackgroundColor(wx.RED)
        self.registerObserver(self.backgroundColorChangedEventType)
        self.categorizable.removeCategory(self.category)
        self.assertEqual(1, len(self.events))

    def testRemoveCategoryWithFont(self):
        self.categorizable.addCategory(self.category)
        self.category.setFont(wx.SWISS_FONT)
        self.registerObserver(self.fontChangedEventType)
        self.categorizable.removeCategory(self.category)
        self.assertEqual(1, len(self.events))

    def testRemoveCategoryWithIcon(self):
        self.categorizable.addCategory(self.category)
        self.category.setIcon('icon')
        self.registerObserver(self.iconChangedEventType)
        self.categorizable.removeCategory(self.category)
        self.assertEqual(1, len(self.events))

    def testForegroundColorWhenOneOutOfTwoCategoriesHasForegroundColor(self):
        self.categorizable.addCategory(self.category)
        self.categorizable.addCategory(category.Category('Another category'))
        self.category.setForegroundColor(wx.RED)
        self.assertEqual(wx.RED, self.categorizable.foregroundColor(recursive=True))
                
    def testBackgroundColorWhenOneOutOfTwoCategoriesHasBackgroundColor(self):
        self.categorizable.addCategory(self.category)
        self.categorizable.addCategory(category.Category('Another category'))
        self.category.setBackgroundColor(wx.RED)
        self.assertEqual(wx.RED, self.categorizable.backgroundColor(recursive=True))

    def testFontWhenOneOutOfTwoCategoriesHasFont(self):
        self.categorizable.addCategory(self.category)
        self.categorizable.addCategory(category.Category('Another category'))
        self.category.setFont(wx.SWISS_FONT)
        self.assertEqual(wx.SWISS_FONT, self.categorizable.font(recursive=True))

    def testIconWhenOneOutOfTwoCategoriesHasIcon(self):
        self.categorizable.addCategory(self.category)
        self.categorizable.addCategory(category.Category('Another category'))
        self.category.setIcon('icon')
        self.assertEqual('icon', self.categorizable.icon(recursive=True))

    def testForegroundColorWhenBothCategoriesHaveSameForegroundColor(self):
        self.categorizable.addCategory(self.category)
        anotherCategory = category.Category('Another category')
        self.categorizable.addCategory(anotherCategory)
        for cat in [self.category, anotherCategory]:
            cat.setForegroundColor(wx.RED)
        self.assertEqual(wx.RED, self.categorizable.foregroundColor(recursive=True))
        
    def testBackgroundColorWhenBothCategoriesHaveSameBackgroundColor(self):
        self.categorizable.addCategory(self.category)
        anotherCategory = category.Category('Another category')
        self.categorizable.addCategory(anotherCategory)
        for cat in [self.category, anotherCategory]:
            cat.setBackgroundColor(wx.RED)
        self.assertEqual(wx.RED, 
                         self.categorizable.backgroundColor(recursive=True))

    def testFontWhenBothCategoriesHaveSameFont(self):
        self.categorizable.addCategory(self.category)
        anotherCategory = category.Category('Another category')
        self.categorizable.addCategory(anotherCategory)
        for cat in [self.category, anotherCategory]:
            cat.setFont(wx.SWISS_FONT)
        self.assertEqual(wx.SWISS_FONT, self.categorizable.font(recursive=True))

    def testIconWhenBothCategoriesHaveSameIcon(self):
        self.categorizable.addCategory(self.category)
        anotherCategory = category.Category('Another category')
        self.categorizable.addCategory(anotherCategory)
        for cat in [self.category, anotherCategory]:
            cat.setIcon('icon')
        self.assertEqual('icon', self.categorizable.icon(recursive=True))

    def testForegroundColorWhenBothCategoriesHaveDifferentForegroundColors(self):
        self.categorizable.addCategory(self.category)
        anotherCategory = category.Category('Another category')
        self.categorizable.addCategory(anotherCategory)
        self.category.setForegroundColor(wx.RED)
        anotherCategory.setForegroundColor(wx.BLUE)
        expectedColor = wx.Color(127, 0, 127, 255)
        self.assertEqual(expectedColor, 
                         self.categorizable.foregroundColor(recursive=True))
                
    def testBackgroundColorWhenBothCategoriesHaveDifferentBackgroundColors(self):
        self.categorizable.addCategory(self.category)
        anotherCategory = category.Category('Another category')
        self.categorizable.addCategory(anotherCategory)
        self.category.setBackgroundColor(wx.RED)
        anotherCategory.setBackgroundColor(wx.BLUE)
        expectedColor = wx.Color(127, 0, 127, 255)
        self.assertEqual(expectedColor, 
                         self.categorizable.backgroundColor(recursive=True))

    def testFontWhenBothCategoriesHaveDifferentFontSizes(self):
        self.categorizable.addCategory(self.category)
        anotherCategory = category.Category('Another category')
        self.categorizable.addCategory(anotherCategory)
        font = wx.SWISS_FONT
        self.category.setFont(font)
        biggerFont = wx.Font(font.GetPointSize() + 2, font.GetFamily(),
                             font.GetStyle(), font.GetWeight())
        anotherCategory.setFont(biggerFont)
        expectedFontSize = (biggerFont.GetPointSize() + font.GetPointSize()) / 2
        self.assertEqual(expectedFontSize, 
                         self.categorizable.font(recursive=True).GetPointSize())

    def testIconWhenBothCategoriesHaveDifferentIcons(self):
        self.categorizable.addCategory(self.category)
        anotherCategory = category.Category('Another category')
        self.categorizable.addCategory(anotherCategory)
        self.category.setIcon('icon')
        anotherCategory.setIcon('another_icon')
        self.failUnless(self.categorizable.icon(recursive=True) in ['icon', 'another_icon'])

    def testUseCategoryIcon(self):
        self.category.setIcon('categoryIcon')
        self.categorizable.addCategory(self.category)
        self.assertEqual('categoryIcon', self.categorizable.icon(recursive=True))

    def testDontUseCategoryIconWhenCategorizableHasItsOwnIcon(self):
        self.category.setIcon('categoryIcon')
        self.categorizable.setIcon('icon')
        self.categorizable.addCategory(self.category)
        self.assertEqual('icon', self.categorizable.icon(recursive=True))

    def testDontUseCategoryIconWhenNotRecursive(self):
        self.category.setIcon('categoryIcon')
        self.categorizable.addCategory(self.category)
        self.failIf(self.categorizable.icon(recursive=False))

    def testUseCategoryIconEvenWhenCategorizableHasARecursiveIcon(self):
        child = categorizable.CategorizableCompositeObject(subject='child')
        self.categorizable.addChild(child)
        self.categorizable.setIcon('icon')
        self.category.setIcon('categoryIcon')
        child.addCategory(self.category)
        self.assertEqual('categoryIcon', child.icon(recursive=True))

    def testUseCategorySelectedIcon(self):
        self.category.setSelectedIcon('categoryIcon')
        self.categorizable.addCategory(self.category)
        self.assertEqual('categoryIcon',
                         self.categorizable.selectedIcon(recursive=True))

    def testDontUseCategorySelectedIconWhenCategorizableHasItsOwnSelectedIcon(self):
        self.category.setSelectedIcon('categoryIcon')
        self.categorizable.setSelectedIcon('icon')
        self.categorizable.addCategory(self.category)
        self.assertEqual('icon',
                         self.categorizable.selectedIcon(recursive=True))

    def testDontUseCategorySelectedIconWhenNotRecursive(self):
        self.category.setSelectedIcon('categoryIcon')
        self.categorizable.addCategory(self.category)
        self.failIf(self.categorizable.selectedIcon(recursive=False))

    def testUseCategorySelectedIconEvenWhenCategorizableHasARecursiveSelectedIcon(self):
        child = categorizable.CategorizableCompositeObject(subject='child')
        self.categorizable.addChild(child)
        self.categorizable.setSelectedIcon('icon')
        self.category.setSelectedIcon('categoryIcon')
        child.addCategory(self.category)
        self.assertEqual('categoryIcon', child.selectedIcon(recursive=True))
    
    def testParentCategoryIncludedInChildRecursiveCategories(self):
        self.categorizable.addCategory(self.category)
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        self.assertEqual(set([self.category]), child.categories(recursive=True))

    def testParentCategoryNotIncludedInChildCategories(self):
        self.categorizable.addCategory(self.category)
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        self.assertEqual(set(), child.categories(recursive=False))
        
    def testGrandParentCategoryIncludedInGrandChildRecursiveCategories(self):
        self.categorizable.addCategory(self.category)
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        grandchild = categorizable.CategorizableCompositeObject()
        child.addChild(grandchild)
        self.assertEqual(set([self.category]), 
                         grandchild.categories(recursive=True))
        
    def testGrandParentAndParentCategoriesIncludedInGrandChildRecursiveCategories(self):
        self.categorizable.addCategory(self.category)
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        grandchild = categorizable.CategorizableCompositeObject()
        child.addChild(grandchild)
        childCategory = category.Category('Child category')
        child.addCategory(childCategory)
        self.assertEqual(set([self.category, childCategory]), 
            grandchild.categories(recursive=True))
        
    def testRemoveCategoryCausesChildNotification(self):
        self.categorizable.addCategory(self.category)
        child = categorizable.CategorizableCompositeObject()
        self.categorizable.addChild(child)
        self.registerObserver(self.totalCategoryRemovedEventType)
        self.categorizable.removeCategory(self.category)
        self.assertEqual([patterns.Event( \
            self.totalCategoryRemovedEventType, child, self.category)], 
            self.events)

    def testCopy(self):
        self.categorizable.addCategory(self.category)
        copy = self.categorizable.copy()
        self.assertEqual(copy.categories(), self.categorizable.categories()) # pylint: disable-msg=E1101
        
    def testModificationEventTypes(self): # pylint: disable-msg=E1003
        self.assertEqual(super(categorizable.CategorizableCompositeObject,
                               self.categorizable).modificationEventTypes() + \
                         [self.categoryAddedEventType, 
                          self.categoryRemovedEventType],
                         self.categorizable.modificationEventTypes())

    
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.