"""Test jednostkowy dla odbchelper.pyTen program jest częścią "Zanurkuj w Pythonie", darmową książką o Pythonie dla zaawansowanych użytkowników. Odwiedź http://diveintopython.org/ i pobierz najnowszą wersję książki."""__author__="Mark Pilgrim (mark@diveintopython.org)"__version__="$Revision: 1.2 $"__date__="$Date: 2004/05/05 21:57:19 $"__copyright__="Copyright (c) 2001 Mark Pilgrim"__license__="Python"importunittestimportodbchelperclassGoodInput(unittest.TestCase):deftestBlank(self):u"""buildConnectionString powinien działać dla pustego słownika"""self.assertEqual("",odbchelper.buildConnectionString({}))deftestKnownValue(self):u"""buildConnectionString powinien zwracać poprawną wartość dla poprawnych danych"""params={"server":"mpilgrim","database":"master","uid":"sa","pwd":"secret"}knownItems=params.items()knownItems.sort()knownString=repr(knownItems)result=odbchelper.buildConnectionString(params)resultItems=[tuple(e.split("="))foreinresult.split(";")]resultItems.sort()resultString=repr(resultItems)self.assertEqual(knownString,resultString)classBadInput(unittest.TestCase):deftestString(self):u"""buildConnectionString powinien zwrócić wyjątek gdy podamy mu łańcuch znaków"""self.assertRaises(AttributeError,odbchelper.buildConnectionString,"")deftestList(self):u"""buildConnectionString powinien zwrócić wyjątek gdy podamy mu listę"""self.assertRaises(AttributeError,odbchelper.buildConnectionString,[])deftestTuple(self):u"""buildConnectionString powinien zwrócić wyjątek gdy podamy mu krotkę"""self.assertRaises(AttributeError,odbchelper.buildConnectionString,())if__name__=="__main__":unittest.main()