Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-10-17 17:47:58 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-10-17 17:47:58 (GMT)
commit3b9bff2ef1826987d95815ff03c235052cea9aae (patch)
treeeac77f7221d54642ee7258e3bc8c2376d65c8900 /tests
parent8ffa6e6e714a560d17e13f909625f143338e785b (diff)
LP 439980 : Code review changes : renamed is_identical to __eq__, relaxed action insertion constraints, added fixed meta-props for addons
Diffstat (limited to 'tests')
-rw-r--r--tests/coretests.py85
-rw-r--r--tests/propertiestests.py32
-rwxr-xr-xtests/run-tests.py77
-rw-r--r--tests/serializertests.py4
4 files changed, 46 insertions, 152 deletions
diff --git a/tests/coretests.py b/tests/coretests.py
index 10cc716..4f564c8 100644
--- a/tests/coretests.py
+++ b/tests/coretests.py
@@ -182,14 +182,11 @@ class StateTest(unittest.TestCase):
assert state.add_action(act2), "Could not add the second action"
assert state.add_action(act3), "Could not add the third action"
- # Try to add a second time an action that was already inserted
- assert state.add_action(act1) == False, "Not supposed to insert an action twice"
-
# Fetch the associated actions
actions = state.get_action_list()
# Make sure all the actions are present in the state
- assert act1 in actions and act2 in actions and act3 in actions,\
+ assert act1 in actions and act2 in actions and act3 in actions, \
"The actions were not properly inserted in the state"
# Clear the list
@@ -225,16 +222,16 @@ class StateTest(unittest.TestCase):
assert len(state.get_event_filter_list()) == 0, \
"Could not clear the event filter list properly"
- def test_is_identical_simple(self):
+ def test_eq_simple(self):
"""
Two empty states with the same name must be identical
"""
st1 = State("Identical")
st2 = State("Identical")
- assert st1.is_identical(st2), "Empty states with the same name should be identical"
+ assert st1 == st2, "Empty states with the same name should be identical"
- def test_is_identical(self):
+ def test_eq(self):
"""
Test whether two states share the same set of actions and event filters.
"""
@@ -261,33 +258,33 @@ class StateTest(unittest.TestCase):
st2.add_event_filter(event1)
# Make sure that they are identical for now
- assert st1.is_identical(st2), "States should be considered as identical"
- assert st2.is_identical(st1), "States should be considered as identical"
+ assert st1 == st2, "States should be considered as identical"
+ assert st2 == st1, "States should be considered as identical"
# Modify the second bubble message action
act2.message = "New message"
# Since one action changed in the second state, this should indicate that the states
# are not identical anymore
- assert st1.is_identical(st2) == False, "Action was changed and states should be different"
- assert st2.is_identical(st1) == False, "Action was changed and states should be different"
+ assert not (st1 == st2), "Action was changed and states should be different"
+ assert not (st2 == st1), "Action was changed and states should be different"
# Make sure that trying to find identity with something else than a State object fails properly
- assert st1.is_identical(non_state) == False, "Passing a non-State object should fail for identity"
+ assert not (st1 == non_state), "Passing a non-State object should fail for identity"
st2.name = "Not identical anymore"
- assert st1.is_identical(st2) == False, "Different state names should give different states"
+ assert not(st1 == st2), "Different state names should give different states"
st2.name = "Identical"
st3 = copy.deepcopy(st1)
st3.add_action(addon.create("BubbleMessage", "Hi!", [128,264]))
- assert st1.is_identical(st3) == False, "States having a different number of actions should be different"
+ assert not (st1 == st3), "States having a different number of actions should be different"
st4 = copy.deepcopy(st1)
st4.add_event_filter(addon.create("GtkWidgetEventFilter", "next_state", "0.0.1.1.2.2.3", "clicked"))
- assert st1.is_identical(st4) == False, "States having a different number of events should be different"
+ assert not (st1 == st4), "States having a different number of events should be different"
st5 = copy.deepcopy(st1)
st5._event_filters = []
@@ -295,7 +292,8 @@ class StateTest(unittest.TestCase):
st5.add_event_filter(addon.create("GtkWidgetEventFilter", "other_state", "0.1.2.3.4.1.2", "pressed"))
#import rpdb2; rpdb2.start_embedded_debugger('pass')
- assert st1.is_identical(st5) == False, "States having the same number of event filters but those being different should be different"
+ assert not (st1 == st5), "States having the same number of event filters" \
+ + " but those being different should be different"
class FSMTest(unittest.TestCase):
"""
@@ -433,10 +431,10 @@ class FSMTest(unittest.TestCase):
# Make sure that there is no link to the removed state in the rest
# of the FSM
- assert "second" not in fsm.get_following_states("INIT"),\
+ assert "second" not in fsm.get_following_states("INIT"), \
"The link to second from INIT still exists after removal"
- assert "second" not in fsm.get_following_states("third"),\
+ assert "second" not in fsm.get_following_states("third"), \
"The link to second from third still exists after removal"
def test_set_same_state(self):
@@ -463,7 +461,7 @@ class FSMTest(unittest.TestCase):
"The action was triggered a second time, do_count = %d"%do_count
undo_count = fsm.get_state_by_name("INIT").get_action_list()[0].undo_count
- assert fsm.get_state_by_name("INIT").get_action_list()[0].undo_count == 0,\
+ assert fsm.get_state_by_name("INIT").get_action_list()[0].undo_count == 0, \
"The action has been undone unappropriately, undo_count = %d"%undo_count
def test_setup(self):
@@ -514,12 +512,12 @@ class FSMTest(unittest.TestCase):
assert str(fsm) == "INIT, Final State, Other State, "
- def test_is_identical(self):
+ def test_eq_(self):
fsm = FiniteStateMachine("Identity test")
non_fsm_object = object()
- assert fsm.is_identical(non_fsm_object) == False, "Testing with non FSM object should not give identity"
+ assert not (fsm == non_fsm_object), "Testing with non FSM object should not give identity"
# Compare FSMs
act1 = CountAction()
@@ -528,19 +526,21 @@ class FSMTest(unittest.TestCase):
fsm2 = copy.deepcopy(fsm)
- assert fsm.is_identical(fsm2)
+ assert fsm == fsm2
act2 = CountAction()
fsm2.add_action(act2)
- assert fsm.is_identical(fsm2) == False, "FSMs having a different number of actions should be different"
+ assert not(fsm == fsm2), \
+ "FSMs having a different number of actions should be different"
fsm3 = FiniteStateMachine("Identity test")
act3 = addon.create("BubbleMessage", "Hi!", [123,312])
fsm3.add_action(act3)
- assert fsm3.is_identical(fsm) == False, "Actions having the same number of actions but different ones should be different"
+ assert not(fsm3 == fsm), \
+ "Actions having the same number of actions but different ones should be different"
st1 = State("INIT")
@@ -551,17 +551,17 @@ class FSMTest(unittest.TestCase):
fsm4 = copy.deepcopy(fsm)
- assert fsm.is_identical(fsm4)
+ assert fsm == fsm4
st3 = State("Last State")
fsm4.add_state(st3)
- assert fsm.is_identical(fsm4) == False, "FSMs having a different number of states should not be identical"
+ assert not (fsm == fsm4), "FSMs having a different number of states should not be identical"
fsm4.remove_state("OtherState")
- assert fsm.is_identical(fsm4) == False, "FSMs having different states should be different"
+ assert not (fsm == fsm4), "FSMs having different states should be different"
fsm4.remove_state("Last State")
@@ -570,7 +570,7 @@ class FSMTest(unittest.TestCase):
fsm4.add_state(st5)
- assert fsm.is_identical(fsm4) == False, "FSMs having states with same name but different content should be different"
+ assert not(fsm == fsm4), "FSMs having states with same name but different content should be different"
class FSMExplorationTests(unittest.TestCase):
def setUp(self):
@@ -627,34 +627,5 @@ class FSMExplorationTests(unittest.TestCase):
self.validate_previous_states("Fourth", ("Second"))
- def test_is_identical(self):
- otherFSM = copy.deepcopy(self.fsm)
-
- assert self.fsm.is_identical(otherFSM), "Copied FSM was different"
-
- # Change the name of the second FSM
- otherFSM.name = "OtherName"
-
- assert self.fsm.is_identical(otherFSM) == False, "Name change should make the FSMs different"
-
- otherFSM.name = self.fsm.name
-
- # Add an extra state to the second FSM
- new_state = State("New State!")
-
- act1 = addon.create("BubbleMessage", message="This will make the second FSM different", position=[100, 0])
- new_state.add_action(act1)
-
- otherFSM.add_state(new_state)
-
- assert self.fsm.is_identical(otherFSM) == False, "The second FSM has an extra state and should not be identical"
-
- otherFSM.remove_state("New State!")
-
- # Test difference with one FSM having an FSM-level action
- otherFSM.add_action(act1)
-
- assert self.fsm.is_identical(otherFSM) == False, "The second FSM has an FSM-level action and should be different"
-
if __name__ == "__main__":
unittest.main()
diff --git a/tests/propertiestests.py b/tests/propertiestests.py
index 03e7814..0b8251a 100644
--- a/tests/propertiestests.py
+++ b/tests/propertiestests.py
@@ -17,6 +17,7 @@
import unittest
import uuid
import os
+import copy
from sugar.tutorius.constraints import *
from sugar.tutorius.properties import *
@@ -84,14 +85,14 @@ class BasePropertyTest(unittest.TestCase):
assert obj.prop == 2, "Unable to set a value on base class"
- def test_is_identical(self):
+ def test_eq_(self):
class klass(TPropContainer):
prop = TutoriusProperty()
obj = klass()
obj2 = klass()
- assert obj.is_identical(obj2), "Base property containers should be identical"
+ assert obj == obj2, "Base property containers should be identical"
class AdvancedPropertyTest(unittest.TestCase):
def test_properties_groups(self):
@@ -104,11 +105,6 @@ class AdvancedPropertyTest(unittest.TestCase):
property = TutoriusProperty()
data = TutoriusProperty()
- class klass2(TPropContainer):
- property = TutoriusProperty()
- message = TutoriusProperty()
- data = TutoriusProperty()
-
class klass3(TPropContainer):
property = TutoriusProperty()
message = TutoriusProperty()
@@ -125,7 +121,7 @@ class AdvancedPropertyTest(unittest.TestCase):
obj1.message = "Initial message"
obj1.data = [132, 208, 193, 142]
- obj2 = klass2()
+ obj2 = klass1()
obj2.property = 12
obj2.message = "Initial message"
obj2.data = [132, 208, 193, 142]
@@ -143,16 +139,20 @@ class AdvancedPropertyTest(unittest.TestCase):
# Ensure that both obj1 and obj2 are identical (they have the same list of
# properties and they have the same values
- assert obj1.is_identical(obj2), "Identical objects were considered as different"
+ assert obj1 == obj1, "Identical objects were considered as different"
# Ensure that obj1 is different from obj3, since obj3 has an extra property
- assert obj1.is_identical(obj3) == False, "Objects should not be identical since obj3 has more props"
- assert obj3.is_identical(obj1) == False, "Objects should not be identical since obj3 has more properties"
+ assert not (obj1 == obj3), "Objects should not be identical since obj3 has more props"
+ assert not (obj3 == obj1), "Objects should not be identical since obj3 has more properties"
# Ensure that properties of different type are considered as different
- assert obj1.is_identical(obj4) == False, "Properties of different type should not be equal"
+ assert not (obj1 == obj4), "Properties of different type should not be equal"
def test_addon_properties(self):
+ """Test an addon property.
+
+ This tests creates a class with a single addon property (klass1) and
+ assigns a new addon to it (inner1)."""
class klass1(TPropContainer):
addon = TAddonProperty()
@@ -168,12 +168,12 @@ class AdvancedPropertyTest(unittest.TestCase):
obj2 = klass1()
obj2.addon = inner1("Hi!")
- assert obj1.is_identical(obj2), "Identical objects with addon proeprties were treated as different"
+ assert obj1 == obj2, "Identical objects with addon properties were treated as different"
obj3 = klass1()
obj3.addon = inner1("Hello!")
- assert obj1.is_identical(obj3) == False, "Objects with addon property having a different value should be considered different"
+ assert not (obj1 == obj3), "Objects with addon property having a different value should be considered different"
def test_addonlist_properties(self):
class klass1(TPropContainer):
@@ -200,11 +200,11 @@ class AdvancedPropertyTest(unittest.TestCase):
obj2 = klass1()
obj2.addon_list = [inner1('Hi!', 12), inner1('Hello.', [1,2])]
- assert obj1.is_identical(obj2), "Addon lists with the same containers were considered different"
+ assert obj1 == obj2, "Addon lists with the same containers were considered different"
obj3 = klass1()
obj3.addon_list = [inner1('Hi!', 12), inner2('Hello.', [1,2])]
- assert obj1.is_identical(obj3) == False, "Differently named proeprties should be considered different in the addon list tests"
+ assert not (obj1 == obj3), "Differently named properties should be considered different in the addon list tests"
class TIntPropertyTest(unittest.TestCase):
def test_int_property(self):
diff --git a/tests/run-tests.py b/tests/run-tests.py
deleted file mode 100755
index beb05ab..0000000
--- a/tests/run-tests.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/usr/bin/python
-# This is a dumb script to run tests on the sugar-jhbuild installed files
-# The path added is the default path for the jhbuild build
-
-INSTALL_PATH="../../../../../../install/lib/python2.5/site-packages/"
-
-import os, sys
-sys.path.insert(0,
- os.path.abspath(INSTALL_PATH)
-)
-
-FULL_PATH = os.path.join(INSTALL_PATH,"sugar/tutorius")
-SUBDIRS = ["uam"]
-GLOB_PATH = os.path.join(FULL_PATH,"*.py")
-import unittest
-from glob import glob
-def report_files():
- ret = glob(GLOB_PATH)
- for dir in SUBDIRS:
- ret += glob(os.path.join(FULL_PATH,dir,"*.py"))
- return ret
-
-import sys
-if __name__=='__main__':
- if "--coverage" in sys.argv:
- sys.argv=[arg for arg in sys.argv if arg != "--coverage"]
- import coverage
- coverage.erase()
- #coverage.exclude('raise NotImplementedError')
- coverage.start()
-
- import coretests
- import servicestests
- import gtkutilstests
- #import overlaytests # broken
- import linear_creatortests
- import actiontests
- import uamtests
- import filterstests
- import constraintstests
- import propertiestests
- import serializertests
- import addontests
- import storetests
- suite = unittest.TestSuite()
- suite.addTests(unittest.findTestCases(coretests))
- suite.addTests(unittest.findTestCases(servicestests))
- suite.addTests(unittest.findTestCases(gtkutilstests))
- #suite.addTests(unittest.findTestCases(overlaytests)) # broken
- suite.addTests(unittest.findTestCases(linear_creatortests))
- suite.addTests(unittest.findTestCases(actiontests))
- suite.addTests(unittest.findTestCases(uamtests))
- suite.addTests(unittest.findTestCases(filterstests))
- suite.addTests(unittest.findTestCases(constraintstests))
- suite.addTests(unittest.findTestCases(propertiestests))
- suite.addTests(unittest.findTestCases(serializertests))
- runner = unittest.TextTestRunner()
- runner.run(suite)
- coverage.stop()
- coverage.report(report_files())
- coverage.erase()
- else:
- from coretests import *
- from servicestests import *
- from gtkutilstests import *
- #from overlaytests import * # broken
- from actiontests import *
- from linear_creatortests import *
- from uamtests import *
- from filterstests import *
- from constraintstests import *
- from propertiestests import *
- from actiontests import *
- from serializertests import *
- from addontests import *
- from storetests import *
- unittest.main()
diff --git a/tests/serializertests.py b/tests/serializertests.py
index c939b7a..2f2e287 100644
--- a/tests/serializertests.py
+++ b/tests/serializertests.py
@@ -164,7 +164,7 @@ class XMLSerializerTest(unittest.TestCase):
self.test_save()
reloaded_fsm = xml_ser.load_fsm(str(self.uuid))
- assert self.fsm.is_identical(reloaded_fsm), "Expected equivalence before saving vs after loading."
+ assert self.fsm == reloaded_fsm, "Expected equivalence before saving vs after loading."
def test_all_filters(self):
"""
@@ -190,7 +190,7 @@ class XMLSerializerTest(unittest.TestCase):
reloaded_fsm = xml_ser.load_fsm(str(self.uuid))
- assert self.fsm.is_identical(reloaded_fsm), "Expected equivalence before saving vs after loading."
+ assert self.fsm == reloaded_fsm, "Expected equivalence before saving vs after loading."
if __name__ == "__main__":
unittest.main()