[Checkins] SVN: Sandbox/J1m/s3uploadqueue/s Finish tests, and make it work.
satchit@zope.com
cvs-admin at zope.org
Fri Jun 15 15:25:14 UTC 2012
Log message for revision 126864:
Finish tests, and make it work.
Changed:
U Sandbox/J1m/s3uploadqueue/setup.py
U Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/README.txt
U Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/__init__.py
U Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/tests.py
-=-
Modified: Sandbox/J1m/s3uploadqueue/setup.py
===================================================================
--- Sandbox/J1m/s3uploadqueue/setup.py 2012-06-15 15:23:17 UTC (rev 126863)
+++ Sandbox/J1m/s3uploadqueue/setup.py 2012-06-15 15:25:11 UTC (rev 126864)
@@ -14,7 +14,7 @@
name, version = 'zc.s3uploadqueue', '0'
install_requires = ['setuptools', 'boto', 'zc.thread']
-extras_require = dict(test=['zope.testing', 'mock'])
+extras_require = dict(test=['zope.testing', 'manuel', 'mock'])
entry_points = """
"""
Modified: Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/README.txt
===================================================================
--- Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/README.txt 2012-06-15 15:23:17 UTC (rev 126863)
+++ Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/README.txt 2012-06-15 15:25:11 UTC (rev 126864)
@@ -72,6 +72,10 @@
.. -> config
+ >>> import os
+ >>> os.mkdir('test')
+ >>> write('queue.cfg', config)
+
If we were to put files in S3, we'd place them in the ``test``
directory. For example, to put data at the key:
``2012-06-14/01.txt``, we'd store the data in the file::
@@ -91,7 +95,8 @@
function and run it::
import zc.s3uploadqueue
- zc.s3uploadqueue.process(config)
+ stop = zc.s3uploadqueue.process('queue.cfg')
+ stop()
.. -> src
@@ -101,17 +106,29 @@
Place some data:
- >>> write(name.strip(), '')
+ >>> write('/'.join(['test', name.strip()]), '')
Start the processor:
- >>> exec(src)
+ >>> exec src
Wait a bit and see that boto was called:
>>> import time
>>> time.sleep(.1)
+The two threads we created setup the necessary connection with S3:
+
>>> import boto.s3.connection, pprint
- >>> pprint(boto.s3.connection.S3Connection.calls)
+ >>> pprint.pprint(boto.s3.connection.S3Connection.mock_calls)
+ [call('42', 'k3y'),
+ call().get_bucket('testbucket'),
+ call('42', 'k3y'),
+ call().get_bucket('testbucket')]
+The file that we put in is processed and uploaded to S3:
+
+ >>> pprint.pprint(boto.s3.key.Key.mock_calls) #doctest: +ELLIPSIS
+ [call(<MagicMock name='S3Connection().get_bucket()' id='...'>),
+ call(<MagicMock name='S3Connection().get_bucket()' id='...'>),
+ call().set_contents_from_filename('test/2012-06-14%2F01.txt')]
Modified: Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/__init__.py
===================================================================
--- Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/__init__.py 2012-06-15 15:23:17 UTC (rev 126863)
+++ Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/__init__.py 2012-06-15 15:25:11 UTC (rev 126864)
@@ -26,25 +26,27 @@
logger = logging.getLogger(__name__)
levels = dict(
- CRITICAL=50
- ERROR=40
- WARNING=30
- INFO=20
- DEBUG=10
- NOTSET=0
+ CRITICAL=50,
+ ERROR=40,
+ WARNING=30,
+ INFO=20,
+ DEBUG=10,
+ NOTSET=0,
)
def process(config=None):
+ return_stop = True
if config is None:
[config] = sys.argv[1:]
+ return_stop = False
parser = ConfigParser.RawConfigParser()
parser.read(config)
- options = dict(dict(parser.items(section)) for section in parser.sections)
+ options = dict((section, dict(parser.items(section))) for section in parser.sections())
logging.basicConfig(level=levels[options['Queue'].get('log-level', 'INFO')])
- queue = queue.Queue
+ queue = Queue.Queue()
srcdir = options['Queue']['directory']
nthreads = int(options['Queue'].get('threads', 9))
poll_interval = int(options['Queue'].get('poll-interval', 9))
@@ -73,7 +75,7 @@
finally:
queue.task_done()
- theads = [zc.thread.Thread(process_queue) for i in range(nthreads)]
+ threads = [zc.thread.Thread(process_queue) for i in range(nthreads)]
running = [1]
def stop():
@@ -94,7 +96,7 @@
for thread in threads:
queue.put(None)
- if testing:
+ if return_stop:
return stop
if __name__ == '__main__':
Modified: Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/tests.py
===================================================================
--- Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/tests.py 2012-06-15 15:23:17 UTC (rev 126863)
+++ Sandbox/J1m/s3uploadqueue/src/zc/s3uploadqueue/tests.py 2012-06-15 15:25:11 UTC (rev 126864)
@@ -16,6 +16,7 @@
import manuel.capture
import manuel.doctest
import manuel.testing
+import mock
import os
import unittest
import zc.s3uploadqueue
@@ -24,28 +25,6 @@
with open(path, 'w') as f:
f.write(s)
-def basic():
- """
-
- >>> os.mkdir('test')
- >>> write('queue.cfg', '''
- ... [Credentials]
- ... aws_access_key_id = 42
- ... aws_secret_access_key = k3y
- ...
- ... [Queue]
- ... directory = test
- ... bucket = testbucket
- ... poll-interval = 1
- ... ''')
-
- >>>
-
- """
-
-
-
-
def setup(test):
setupstack.setUpDirectory(test)
s3conn = setupstack.context_manager(
@@ -59,15 +38,12 @@
manuel.testing.TestSuite(
manuel.doctest.Manuel() + manuel.capture.Manuel(),
'README.txt',
+ globs={'write': write},
setUp=setup, tearDown=setupstack.tearDown,
),
- # doctest.DocTestSuite(
- # setUp=setup, tearDown=setupstack.tearDown()
- # ),
))
-def test_suite():
More information about the checkins
mailing list