def __init__(self, **kwargs): if not all([self.country, self.bank_code]): raise RuntimeError('Bank is an abstract class and must not be instantiated. ' 'Use its subclasses instead - via Bank.get(bank_code, country).') self.branch = smarter_zfill(kwargs['branch'], self.branch_length) self.branch_digit = smarter_zfill(kwargs.get('branch_digit', ''), self.branch_digit_length) self.account = smarter_zfill(kwargs['account'], self.account_length) self.account_digit = smarter_zfill(kwargs.get('account_digit', ''), self.account_digit_length) if len(self.branch) != self.branch_length: raise InvalidBranchlength(self) if len(self.branch_digit) < self.branch_digit_length: raise MissingBranchDigit(self) if len(self.branch_digit) > self.branch_digit_length: raise UnexpectedBranchDigit(self) if len(self.account) != self.account_length: raise InvalidAccountlength(self) if len(self.account_digit) < self.account_digit_length: raise MissingAccountDigit(self) if len(self.account_digit) > self.account_digit_length: raise UnexpectedAccountDigit(self)
def __init__(self, **kwargs): if not all([self.country, self.bank_code]): raise RuntimeError( 'Bank is an abstract class and must not be instantiated. ' 'Use its subclasses instead - via Bank.get(bank_code, country).' ) self.branch = smarter_zfill(kwargs['branch'], self.branch_length) self.branch_digit = smarter_zfill(kwargs.get('branch_digit', ''), self.branch_digit_length) self.account = smarter_zfill(kwargs['account'], self.account_length) self.account_digit = smarter_zfill(kwargs.get('account_digit', ''), self.account_digit_length) if len(self.branch) != self.branch_length: raise InvalidBranchlength(self) if len(self.branch_digit) < self.branch_digit_length: raise MissingBranchDigit(self) if len(self.branch_digit) > self.branch_digit_length: raise UnexpectedBranchDigit(self) if len(self.account) != self.account_length: raise InvalidAccountlength(self) if len(self.account_digit) < self.account_digit_length: raise MissingAccountDigit(self) if len(self.account_digit) > self.account_digit_length: raise UnexpectedAccountDigit(self)
def test_remove_leading_zeroes(self): self.assertEquals(smarter_zfill('0000000000001', 4), '0001')
def test_common_zfill(self): self.assertEquals(smarter_zfill('1', 4), '0001')
def test_if_expected_length_is_None_just_remove_leading_zeroes(self): self.assertEquals(smarter_zfill('0000000000001'), '1')
def test_None(self): self.assertEquals(smarter_zfill(None, 4), '')
def test_empty_string(self): self.assertEquals(smarter_zfill('', 4), '')
def test_integer(self): self.assertEquals(smarter_zfill(1, 4), '0001')
def test_common_zfill(self): self.assertEqual(smarter_zfill('1', 4), '0001')
def test_if_expected_length_is_None_just_remove_leading_zeroes(self): self.assertEqual(smarter_zfill('0000000000001'), '1')
def test_None(self): self.assertEqual(smarter_zfill(None, 4), '')
def test_empty_string(self): self.assertEqual(smarter_zfill('', 4), '')
def test_integer(self): self.assertEqual(smarter_zfill(1, 4), '0001')
def test_remove_leading_zeroes(self): self.assertEqual(smarter_zfill('0000000000001', 4), '0001')