Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Add a doctest suite
Browse files Browse the repository at this point in the history
  • Loading branch information
pcardune committed Nov 9, 2011
1 parent 6fadd82 commit 7ebaa34
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
Binary file added icon.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -38,6 +38,7 @@
'Operating System :: OS Independent',
'Topic :: Utilities',
],
test_suite = "fbconsole.test_suite",
entry_points = """
[console_scripts]
fbconsole = fbconsole:shell
Expand Down
27 changes: 21 additions & 6 deletions src/fbconsole.py
Expand Up @@ -26,6 +26,7 @@
import time
import types
import urllib2
import urllib
import webbrowser

from urlparse import urlparse, parse_qs
Expand Down Expand Up @@ -208,8 +209,7 @@ def graph_url(path, params=None):
download a large profile picture of Mark Zuckerberg:
>>> url = graph_url('/zuck/picture', {"type":"large"})
>>> import urllib
>>> urllib.urlretrieve(url, 'mark.jpg')
>>> filename, response = urllib.urlretrieve(url, 'mark.jpg')
"""
return _get_url(path, args=params)
Expand All @@ -219,8 +219,12 @@ def get(path, params=None):
For example:
>>> get('/me')
>>> get('/me', {'fields':'id,name'})
>>> user = get('/me')
>>> print user['first_name']
David
>>> short_user = get('/me', {'fields':'id,first_name'})
>>> print short_user['id'], short_user['first_name']
100003169144448 David
"""
return json.load(urllib2.urlopen(_get_url(path, args=params)))
Expand All @@ -230,9 +234,11 @@ def post(path, params=None):
You can also upload files using this function. For example:
>>> post('/me/photos',
>>> photo_id = post('/me/photos',
... {'name': 'My Photo',
... 'source': open("myphoto.jpg")})
... 'source': open("icon.gif")})['id']
>>> print get('/'+photo_id)['name']
My Photo
"""
opener = urllib2.build_opener(
Expand All @@ -247,6 +253,7 @@ def delete(path, params=None):
>>> msg_id = post('/me/feed', {'message':'hello world'})['id']
>>> delete('/'+msg_id)
True
"""
if not params:
Expand All @@ -260,6 +267,7 @@ def fql(query):
For example:
>>> fql('SELECT name FROM user WHERE uid = me()')
[{u'name': u'David Amcafiaddddh Yangstein'}]
"""
url = _get_url('/method/fql.query',
Expand Down Expand Up @@ -291,5 +299,12 @@ def shell():
import code
code.InteractiveConsole(globals()).interact(INTRO_MESSAGE)


def test_suite():
import doctest
global ACCESS_TOKEN
ACCESS_TOKEN = 'AAACjeiZB6FgIBAB8eZABg7So8ALDisFLugfIJSZCg3FEDRy82yEmdXYYfNvdv2kWVMWxaJgWqqVMPtG5v5n4lMG5VXmZBZBykQkeluhpFPQZDZD'
return doctest.DocTestSuite()

if __name__ == '__main__':
shell()

0 comments on commit 7ebaa34

Please sign in to comment.