Created
January 27, 2012 12:55
-
-
Save gregarmer/1688646 to your computer and use it in GitHub Desktop.
Tests showing incorrect address logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
class Listing(object): | |
""" | |
>>> foo = Listing(street_number=123, street_name="Foo drive") | |
>>> foo.address() | |
'123 Foo drive' | |
""" | |
unit_number = None | |
complex_name = None | |
street_number = None | |
street_name = None | |
def __init__(self, *a, **kw): | |
for k, v in kw.items(): | |
if hasattr(self, k): | |
setattr(self, k, v) | |
def address(self): | |
if self.street_number and self.street_name: | |
return "%s %s" % (self.street_number, self.street_name) | |
elif self.street_name and not self.street_number: | |
return self.street_name | |
elif self.unit_number and self.complex_name: | |
return "%s %s" % (self.unit_number, self.complex_name) | |
elif self.complex_name and not self.unit_number: | |
return self.complex_name | |
class TestAddress(unittest.TestCase): | |
def setUp(self): | |
self.street_name_only = Listing(street_name="123 Foo drive") | |
self.full_street_only = Listing(street_number=123, | |
street_name="Foo drive") | |
self.full_address = Listing(unit_number=10, complex_name="ComplexA", | |
street_number=123, street_name="Foo drive") | |
def test_street_name_only(self): | |
self.assertEqual(self.street_name_only.address(), "123 Foo drive") | |
def test_full_street_only(self): | |
self.assertEqual(self.full_street_only.address(), "123 Foo drive") | |
def test_full_address(self): | |
self.assertEqual(self.full_address.address(), | |
"10 ComplexA, 123 Foo drive") | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment