Skip to main content

Decorator for making quick mock csv files for testing.

Project description

QuikCSV

Python package for quickly creating temporary csv files to help with testing. The CSV file exists in memory only so you can create files on the fly without needing to cleanup or delete files later. No need to use with statements or close resources, that is taken care of.

Installation

Not ready just yet.

Sample

Take a function that takes an open CSV file as its argument. Instead of creating and opening an actual CSV file on the disk, decorate the function.

from quikcsv import QuikCSV


@QuikCSV([dict(
    data=[
        ['Column A', 'Column B', 'Column C'],
        ['100',      '101',      '102']
    ]
)])
def csv_func(csv_file):
    # Work with csv file here.
    #
    # QuikCSV.one will map the data above to mimic a csv file with the 
    # respective columns and rows, passing the file to the csv_file argument
    # (or by default, the first argument if there are multiple.)

If you want, you can specify the argument that the CSV mock file will be passed to.

@QuikCSV([dict(
    data=[
        ['Column A', 'Column B', 'Column C'],
        ['100',      '101',      '102']
    ],
    arg='csv_file'
)])
def csv_func(first_arg, csv_file, third_arg):
    # Mock CSV will be accessible on the csv_file variable.

Options can be passed via the opts argument to quickly generate additional rows of data from existing rows.

@QuikCSV([dict(
    data=[
        ['Column A', 'Column B', 'Column C'],
        ['100',      '101',      '102']
    ], 
    opts=dict(
        add_rows=2,
        row_pattern='copy',
        base_row_index=1
    )
)])
def csv_func(csv_file):
    # Output csv file will look like this:
    # 
    # Column A, Column B, Column C
    # 100,      101,      102
    # 100,      101,      102
    # 100,      101,      102
    # 
    # 2 rows of data are added, copied from index 1 of the passed data.

'copy' is a predefined row creation pattern to make things easy, but you can also pass a custom function

@QuikCSV([dict(
    data=[
        ['Column A', 'Column B', 'Column C'],
        ['100',      '101',      '102']
    ], 
    opts=dict(
        add_rows=2,
        row_pattern=lambda x: [n + 1 for n in x],
        base_row_index=1
    )
)])
def csv_func(csv_file):
    # Output csv file will look like this:
    # 
    # Column A, Column B, Column C
    # 100,      101,      102
    # 101,      102,      103
    # 101,      102,      103
    # 
    # The passed function should apply against the row of data, not the 
    # individual element.

The above example applies the same function to the same row again and again, but by setting the 'incremental' option to True, the function will apply the newly created row of data on the next iteration.

@QuikCSV([dict(
    data=[
        ['Column A', 'Column B', 'Column C'],
        ['100',      '101',      '102']
    ], 
    opts=dict(
        add_rows=2,
        row_pattern=lambda x: [n + 1 for n in x],
        base_row_index=1,
        increment=True
    )
)])
def csv_func(csv_file):
    # Output csv file will look like this:
    # 
    # Column A, Column B, Column C
    # 100,      101,      102
    # 101,      102,      103
    # 102,      103,      104
    # 

Features in the works

  • Random data generation - completely random or pseudo-random via user defined options

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quikcsv-0.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quikcsv-0.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file quikcsv-0.1.tar.gz.

File metadata

  • Download URL: quikcsv-0.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for quikcsv-0.1.tar.gz
Algorithm Hash digest
SHA256 619015c08042bf83625369c4c89c056cf5ad05c315c618cc9b256819985887d8
MD5 d0dc1bd2b4e174bcf3e3bce13c6f41cd
BLAKE2b-256 b9ffe23d626175a346565f0505ccd4e37f72ca361a030cc576605b3c17ac68ff

See more details on using hashes here.

File details

Details for the file quikcsv-0.1-py3-none-any.whl.

File metadata

  • Download URL: quikcsv-0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for quikcsv-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1b32cbc23c59df620622345fb4254a9a208db21012c2f6326ee6cc4a47401486
MD5 a2c2a5566da097dd8090c5ec3660666e
BLAKE2b-256 27025892aba19c48c36860c5aac382b2e5636bde206a438bbc4803dced418a91

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page