Changeset 4902 for waeup


Ignore:
Timestamp:
27 Jan 2010, 12:11:32 (15 years ago)
Author:
uli
Message:

Update tests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/trunk/src/waeup/utils/batching.txt

    r4895 r4902  
    226226
    227227    >>> processor = CaveProcessor()
    228     >>> processor.doImport('newcomers.csv',
     228    >>> result = processor.doImport('newcomers.csv',
    229229    ...                   ['name', 'dinoports', 'owner', 'taxpayer'],
    230230    ...                    mode='create', user='Bob', logger=logger)
     231    >>> result
    231232    (4, 0, '/.../newcomers.finished.csv', None)
    232233
     
    263264provided a logger during the call:
    264265
    265     >>> #print open('newcomers.csv.create.msg').read()
    266266    >>> print open('stoneville.log').read()
    267267    --------------------
     
    274274    --------------------
    275275
     276We cleanup the temporay dir created by doImport():
     277
     278    >>> import shutil
     279    >>> import os
     280    >>> shutil.rmtree(os.path.dirname(result[2]))
     281
    276282As we can see, the processing was successful. Otherwise, all problems
    277283could be read here as we can see, if we do the same operation again:
    278284
    279     >>> processor.doImport('newcomers.csv',
     285    >>> result = processor.doImport('newcomers.csv',
    280286    ...                   ['name', 'dinoports', 'owner', 'taxpayer'],
    281287    ...                    mode='create', user='Bob', logger=logger)
     288    >>> result
    282289    (4, 4, '/.../newcomers.finished.csv', '/.../newcomers.pending.csv')
    283290
     
    286293The log file will tell us this in more detail:
    287294
    288     >>> #print open('newcomers.csv.create.msg').read()
    289295    >>> print open('stoneville.log').read()
    290296    --------------------
     
    303309process and an additional column with error messages:
    304310
    305     >>> print open('newcomers.pending.csv').read()
     311    >>> print open(result[3]).read()
    306312    owner,name,taxpayer,dinoports,--ERRORS--
    307313    Barney,Barneys Home,1,2,This object already exists. Skipping.
     
    317323``False`` (which is accepted by the converters).
    318324
     325Clean up:
     326
     327    >>> shutil.rmtree(os.path.dirname(result[2]))
    319328
    320329Updating entries
     
    324333mode:
    325334
    326     >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'],
     335    >>> result = processor.doImport('newcomers.csv', ['name',
     336    ...                             'dinoports', 'owner'],
    327337    ...                    mode='update', user='Bob')
     338    >>> result
    328339    (4, 0, '...', None)
    329340
     
    339350    1
    340351
     352Clean up:
     353
     354    >>> shutil.rmtree(os.path.dirname(result[2]))
     355
     356
    341357We start the processor:
    342358
    343     >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'],
    344     ...                    mode='update', user='Bob')
     359    >>> result = processor.doImport('newcomers.csv', ['name',
     360    ...                    'dinoports', 'owner'], mode='update', user='Bob')
     361    >>> result
    345362    (1, 0, '...', None)
    346363
     
    351368Wilma's number of dinoports raised.
    352369
     370Clean up:
     371
     372    >>> shutil.rmtree(os.path.dirname(result[2]))
     373
     374
    353375If we try to update an unexisting entry, an error occurs:
    354376
     
    358380    ... """)
    359381
    360     >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'],
     382    >>> result = processor.doImport('newcomers.csv', ['name',
     383    ...                             'dinoports', 'owner'],
    361384    ...                    mode='update', user='Bob')
     385    >>> result
    362386    (1, 1, '/.../newcomers.finished.csv', '/.../newcomers.pending.csv')
     387
     388Clean up:
     389
     390    >>> shutil.rmtree(os.path.dirname(result[2]))
     391
    363392   
    364393Also invalid values will be spotted:
     
    369398    ... """)
    370399
    371     >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'],
     400    >>> result = processor.doImport('newcomers.csv', ['name',
     401    ...                             'dinoports', 'owner'],
    372402    ...                    mode='update', user='Bob')
     403    >>> result
    373404    (1, 1, '...', '...')
     405
     406Clean up:
     407
     408    >>> shutil.rmtree(os.path.dirname(result[2]))
     409
    374410
    375411We can also update only some cols, leaving some out. We skip the
     
    381417    ... """)
    382418
    383     >>> processor.doImport('newcomers.csv', ['name', 'owner'],
    384     ...                    mode='update', user='Bob')
     419    >>> result = processor.doImport('newcomers.csv', ['name', 'owner'],
     420    ...                             mode='update', user='Bob')
     421    >>> result
    385422    (1, 0, '...', None)
    386423
    387424    >>> wilma.owner
    388425    u'Barney'
     426
     427Clean up:
     428
     429    >>> shutil.rmtree(os.path.dirname(result[2]))
     430
    389431
    390432We can however, not leave out the 'location field' ('name' in our
     
    412454    ... """)
    413455
    414     >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'],
     456    >>> result = processor.doImport('newcomers.csv', ['name',
     457    ...                             'dinoports', 'owner'],
    415458    ...                    mode='update', user='Bob')
     459    >>> result
    416460    (1, 0, '...', None)
    417461
     
    419463    True
    420464
     465Clean up:
     466
     467    >>> shutil.rmtree(os.path.dirname(result[2]))
     468
    421469Generally, empty strings are considered as ``None``:
    422470
     
    426474    ... """)
    427475
    428     >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'],
     476    >>> result = processor.doImport('newcomers.csv', ['name',
     477    ...                             'dinoports', 'owner'],
    429478    ...                    mode='update', user='Bob')
     479    >>> result
    430480    (1, 0, '...', None)
    431481
     
    433483    True
    434484
     485Clean up:
     486
     487    >>> shutil.rmtree(os.path.dirname(result[2]))
     488
     489
    435490Removing entries
    436491----------------
     
    444499    ... """)
    445500
    446     >>> processor.doImport('newcomers.csv', ['name', 'dinoports', 'owner'],
     501    >>> result = processor.doImport('newcomers.csv', ['name',
     502    ...                             'dinoports', 'owner'],
    447503    ...                    mode='remove', user='Bob')
     504    >>> result
    448505    (1, 0, '...', None)
    449506
     
    453510Oops! Wilma is gone.
    454511
     512Clean up:
     513
     514    >>> shutil.rmtree(os.path.dirname(result[2]))
     515
    455516
    456517Clean up:
     
    458519    >>> import os
    459520    >>> os.unlink('newcomers.csv')
    460     >>> os.unlink('newcomers.finished.csv')
    461521    >>> os.unlink('stoneville.log')
Note: See TracChangeset for help on using the changeset viewer.