# Homework #2¶

Due Feb 6th at 11:59pm. If you work in a group, please work in a group distinct from those you work with in the class.

1. Clone my cse491-drinkz repository into your own directory tree and set up your own github repo as origin, and mine as ‘ctb’:

git clone https://github.com/ctb/cse491-drinkz.git
git remote rm origin
git remote add ctb https://github.com/ctb/cse491-drinkz.git

Next, remove your master branch and replace it with mine:

git push origin :master  # this deletes your master branch
git push origin master:master  # this replaces it with mine

(After all of this, ‘git diff origin/master’ should return no differences. If you’re not sure, check with someone!)

2. Using load_bulk_data.load_bottle_types as inspiration, modify the bulk loading functions to ignore empty lines (note: ‘if not line.strip()’) and ‘#’-commented lines. Write tests for this functionality to make sure it works; the tests should check each piece of functionality separately.

3. Next, write a generic generator wrapper around the ‘csv.reader’ that eliminates commented lines and whitespace lines. You should have one function that can be used by all the bulk loading functions; for example,

for mfg, name, typ in new_reader:

...

should now work. Make sure that all your tests still pass!

4. Implement try/except wrappers around each individual line so that malformed lines in the bulk loading functions simply print out an error rather than failing. (See ‘test_add_to_inventory_2’ in test_drinkz.py for the basic formatting of exception handling.)

5. Fix get_liquor_amount to correctly sum different types of liquor in oz and ml, and report in ml. Write tests to make sure it works properly!

6. Add a script in the main directory called ‘show-liquor-amounts’ that reports the amounts of liquor that you have, as well as the types. (You can base it off the script ‘show-liquor-types’.) Don’t bother writing any tests for this one.

8. Push all your homework to your github repo and send me a pull request.

#### Previous topic

Day 9 – Tu, Feb 5th, 2013

#### Next topic

Day 8 – Th, Jan 31, 2013

### Edit this document!

This file can be edited directly through the Web. Anyone can update and fix errors in this document with few clicks -- no downloads needed.

1. Go to Homework #2 on GitHub.