Example #1
0
def csvdata(csv_file, env_prefix=None):
    """
    Method decorator to use CSV data driven tests.

    Should be added to methods of instances of ``unittest.TestCase``.

    Args:
        csv_file (str) : name of CSV file

    Kwargs:
        env_prefix (str) : subfolder of /data directory to pull csv file from.

    Example::

        @csvdata('mydatafile.csv', env_prefix='qa')
        def test_datadriven_test(data):
            print("column1 data is:", data['column1_name'])


    """
    entry_list = []
    try:
        csv_file = CsvReader(
            WTF_DATA_MANAGER.get_data_path(csv_file, env_prefix))
        while True:
            entry_list.append(csv_file.next())
    except StopIteration:
        pass
    values = tuple(entry_list)

    def wrapper(func):
        setattr(func, MAGIC, values)
        return func
    return wrapper
Example #2
0
    def test_csv_reader_reads_csv_file(self):
        csvreader = CsvReader(WTF_DATA_MANAGER.get_data_path("testdata.csv", "testenv"))
        first_row = csvreader.next()
        self.assertEqual("Dog", first_row['Animal'])
        self.assertEqual("3.0", first_row['Size'])

        second_row = csvreader.next()
        self.assertEqual("Cat", second_row['Animal'])
        self.assertEqual("Mammal", second_row['Type'])

        third_row = csvreader.next()
        self.assertEqual("Reptile", third_row['Type'])
        self.assertEqual("2.0", third_row['Size'])

        self.assertRaises(StopIteration, csvreader.next)
Example #3
0
    def test_csv_reader_reads_csv_file(self):
        csvreader = CsvReader(
            WTF_DATA_MANAGER.get_data_path("testdata.csv", "testenv"))
        first_row = csvreader.next()
        self.assertEqual("Dog", first_row['Animal'])
        self.assertEqual("3.0", first_row['Size'])

        second_row = csvreader.next()
        self.assertEqual("Cat", second_row['Animal'])
        self.assertEqual("Mammal", second_row['Type'])

        third_row = csvreader.next()
        self.assertEqual("Reptile", third_row['Type'])
        self.assertEqual("2.0", third_row['Size'])

        self.assertRaises(StopIteration, csvreader.next)
Example #4
0
def csvdata(csv_file, env_prefix=None):
    """
    Method decorator to use CSV data driven tests.

    Should be added to methods of instances of ``unittest.TestCase``.
    """
    entry_list = []
    try:
        csv_file = CsvReader(WTF_DATA_MANAGER.get_data_path(csv_file, env_prefix))
        while True:
            entry_list.append(csv_file.next())
    except StopIteration:
        pass 
    values = tuple(entry_list)
    
    def wrapper(func):
        setattr(func, MAGIC, values)
        return func
    return wrapper