00001 # Copyright (c) 2013, Felix Kolbe 00002 # All rights reserved. BSD License 00003 # 00004 # Redistribution and use in source and binary forms, with or without 00005 # modification, are permitted provided that the following conditions 00006 # are met: 00007 # 00008 # * Redistributions of source code must retain the above copyright 00009 # notice, this list of conditions and the following disclaimer. 00010 # 00011 # * Redistributions in binary form must reproduce the above copyright 00012 # notice, this list of conditions and the following disclaimer in the 00013 # documentation and/or other materials provided with the distribution. 00014 # 00015 # * Neither the name of the {organization} nor the names of its 00016 # contributors may be used to endorse or promote products derived 00017 # from this software without specific prior written permission. 00018 # 00019 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00020 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00021 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00022 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00023 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00025 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00026 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00027 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00029 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 00031 00032 import unittest 00033 00034 from rgoap.common import Condition 00035 00036 00037 class ConditionTest(unittest.TestCase): 00038 00039 00040 def setUp(self): 00041 Condition._conditions_dict.clear() # start every test without previous conditions 00042 00043 self.condition1 = Condition('name1') 00044 self.condition2 = Condition('name2') 00045 00046 00047 def tearDown(self): 00048 pass 00049 00050 00051 def testAdd(self): 00052 self.assertIs(Condition.add(self.condition1), None, 'Could not add new condition') 00053 self.assertIs(Condition.add(self.condition2), None, 'Could not add another new condition') 00054 00055 def testAddSame(self): 00056 self.assertIs(Condition.add(self.condition1), None, 'Could not add new condition') 00057 self.assertRaises(AssertionError, Condition.add, self.condition1) # 'Could not add another new condition') 00058 00059 def testGet(self): 00060 self.assertRaises(AssertionError, Condition.get, 'name_inexistent') # 'Does not fail on getting inexistent condition') 00061 00062 def testGetSame(self): 00063 self.assertIs(Condition.add(self.condition1), None, 'Could not add new condition') 00064 self.assertIs(Condition.get('name1'), self.condition1, 'Could not get that same condition') 00065 00066 00067 00068 if __name__ == "__main__": 00069 #import sys;sys.argv = ['', 'Test.testName'] 00070 unittest.main()