Skip to content

Instantly share code, notes, and snippets.

View keybase.md

Keybase proof

I hereby claim:

  • I am andy47 on github.
  • I am andy47 (https://keybase.io/andy47) on keybase.
  • I have a public key ASAr8XqLaXRk2O6C-l37nEJckWiUyI3rI9yMsmjPCxkxDgo

To claim this, I am signing this object:

@andy47
andy47 / refactoring_candidate.py
Last active Dec 19, 2015
Example code to show refactoring opportunity
View refactoring_candidate.py
class Portfolio(object):
...
def get_portfolio(self, portfolio_code):
...
stmt = """SELECT id FROM portfolios WHERE code=?"""
cursor.execute(stmt, (portfolio_code,))
portfolio_id = cursor.fetchone()[0]
...
def add_value(self, portfolio_code, ...):
...
@andy47
andy47 / parse_conn_pytest.py
Created Jun 29, 2013
py.test test case for our example function
View parse_conn_pytest.py
from parse_conn import parse_connection
import py.test
def test_not_at():
py.test.raises(ValueError, parse_connection, 'invalid uri')
@andy47
andy47 / parse_conn_unittest.py
Last active Dec 19, 2015
Unittest tests for our example function.
View parse_conn_unittest.py
from parse_conn import parse_connection
import unittest
class InvalidInputs(unittest.TestCase):
def testNoAt(self):
"""parse_connection should raise an exception
for an invalid connection string"""
self.assertRaises(ValueError, parse_connection, 'invalid uri')
if __name__ == "__main__":
@andy47
andy47 / parse_conn.py
Created Jun 29, 2013
An example function for us to write tests for
View parse_conn.py
def parse_connection(connection_string):
"""Work out the user name and password in connection_string
Connection string should be of the form 'database://username@password'
"""
if '@' in connection_string:
# Username is characters between '://' and '@'
slash_position = connection_string.find('://')
at_position = connection_string.find('@')
user_name = connection_string[slash_position+3:at_position]