Handle simple scalar attributes in constructor

This commit is contained in:
Vincent Jacques
2012-02-12 14:25:48 +01:00
parent d91890a2d2
commit e1a0747fe6
2 changed files with 59 additions and 7 deletions
+20 -3
View File
@@ -1,9 +1,16 @@
import unittest
import MockMockMock
from GithubObject import GithubObject, SimpleScalarAttributes
from GithubObject import BadGithubObjectException, GithubObject, SimpleScalarAttributes
class TestCase( unittest.TestCase ):
class GithubObjectTestCase( unittest.TestCase ):
def testDuplicatedAttribute( self ):
with self.assertRaises( BadGithubObjectException ):
GithubObject( "", SimpleScalarAttributes( "a", "a" ) )
with self.assertRaises( BadGithubObjectException ):
GithubObject( "", SimpleScalarAttributes( "a" ), SimpleScalarAttributes( "a" ) )
class TestCaseWithGithubTestObject( unittest.TestCase ):
def setUp( self ):
unittest.TestCase.setUp( self )
self.g = MockMockMock.Mock( "github" )
@@ -13,7 +20,7 @@ class TestCase( unittest.TestCase ):
self.g.tearDown()
unittest.TestCase.tearDown( self )
class GithubObjectWithOnlySimpleAttributes( TestCase ):
class GithubObjectWithOnlySimpleAttributes( TestCaseWithGithubTestObject ):
GithubTestObject = GithubObject(
"GithubTestObject",
SimpleScalarAttributes( "a1", "a2", "a3", "a4" )
@@ -22,4 +29,14 @@ class GithubObjectWithOnlySimpleAttributes( TestCase ):
def testConstruction( self ):
pass # Everything is done in setUp/tearDown
def testCompletion( self ):
# A GithubObject:
# - knows the attributes given to its constructor
self.assertEqual( self.o.a1, 1 )
self.assertEqual( self.o.a2, 2 )
def testUnknownAttribute( self ):
# A GithubObject:
# - does not have silly attributes
self.assertRaises( AttributeError, lambda: self.o.foobar )
unittest.main()