Python Forum
How to make a test data file for the full length of definition?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make a test data file for the full length of definition?
#1
How to make a test data file for the full length of definition?
================================================================

Thanks for your replies to my threads. Smile

I am looking to make test data file to satisfy the full length of the field definition.

For instance, with this data structure:

Name varchar (10)
Business Name varchar (15)
Address Varchar (20)

there are many more fields around 70-80 after the above sample

Test file to be with '|' delimiter (field separator)

The output like:

xxxxxxxxxx|uuuuuuuuuuuuuuu|pppppppppppppppppppp

The above is a sample. The fields can be filled with fake characters

If Numeric like number (9,2) with digits

If a character like varchar (20) mix of alphabets & digits

some files use ASCII '\031' as a delimiter.

I tried to do this with excel, I couldn't figure it out. I need forum's guidance.

Are we able to do this with Python code? Rolleyes

How do I do that?

Thanks for your guidance.
Reply
#2
Are you looking for something like this?

lengths = (10, 15, 20)
with open ('test.csv', 'w') as test_file :
	for character_number in range (65, 122, 1) :
		for field_length in lengths :
			output = chr (character_number) * field_length + '|'
			test_file.write (output)
Reply
#3
Thanks for weighing in.

I see the output from this python script comes as

of 2736 character length.

lengths = (10, 15, 20) defines the length of 3 fields.

The need is not to repeat these 3 sets many times upto 2736 characters

The record structure will have 70-80 fields with mixed types/length like

Name varchar (10)
Business Name varchar (15)
Address Varchar (20)
amount number(12,2)
amount2 number (7,2)
rate number (5,2)
C_name varchar (32)
*
*
*
*
*
*
*

goes to many field definitions upto 70-80



How do I make the output for

If Numeric like number (9,2) with digits

If a character like varchar (20) mix of alphabets & digits

some files use ASCII '\031' as a delimiter. How do I do that in above scripts.

Thanks for your help.

UPDATE
=======


I like to add clarifications to this question:

I have the required spec in a file like

colspec1.data

cat colspec1.data
10,x
15,u
20,p
10,9
22,w
18,r
15,9
This help me to add many rows as needed.

The changed Python script looks like

from csv import reader
final_string = ''
# read csv file as a list of lists
with open('colspec1.data', 'r') as read_obj:
    # pass the file object to reader() to get the reader object
    csv_reader = reader(read_obj)
    # Pass reader object to list() to get a list of lists
    data = list(map(tuple, csv_reader))

    for length, character in data:
        print(int(length))
        final_string += int(length) * str(character) + '|'

print(final_string)
The OUTPUT from this script is

10
15
20
10
22
18
15
xxxxxxxxxx|uuuuuuuuuuuuuuu|pppppppppppppppppppp|9999999999|wwwwwwwwwwwwwwwwwwwwww|rrrrrrrrrrrr
How can I change ASCII '\031' as delimiter instead of '|' in this code ?

Any suggestions for improvement in this script?

I am looking to add date data, amount like 9999999.99 as well.

Thanks for your guidance.

Thanks for your guidance.
Reply
#4
any thoughts ?
Reply
#5
Is the record structure you show above correct? Is there a difference between "varchar" and "Varchar"? Do you have any types beside varchar and number?
Reply
#6
I'm not really sure what you're asking, but it makes me think of property-based testing. For that, there's Hypothesis.
Reply
#7
Thanks for weighing in.

I updated my question with additional info.

There is no difference between "varchar" and "Varchar".

Do you have any types beside varchar and number? Good question

Date (YYYY/MM/DD) & a havemount (9999999999.99) nice to have.

Thanks for your help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  mutable argument in function definition akbarza 1 423 Dec-15-2023, 02:00 PM
Last Post: deanhystad
  error occuring in definition a class akbarza 3 636 Nov-26-2023, 09:28 AM
Last Post: Yoriz
  determine parameter type in definition function akbarza 1 550 Aug-24-2023, 01:46 PM
Last Post: deanhystad
  unittest generates multiple files for each of my test case, how do I change to 1 file zsousa 0 918 Feb-15-2023, 05:34 PM
Last Post: zsousa
  shutil.move make data corrupt kucingkembar 0 743 Feb-01-2023, 01:30 PM
Last Post: kucingkembar
  [split] Explain the python code in this definition Led_Zeppelin 1 711 Jan-13-2023, 10:20 PM
Last Post: deanhystad
  Explain the python code in this definition Led_Zeppelin 1 1,059 Oct-27-2022, 04:04 AM
Last Post: deanhystad
  How to sort .csv file test log which item first fail and paint color SamLiu 24 4,701 Sep-03-2022, 07:32 AM
Last Post: Pedroski55
  meaning of -> syntax in function definition DrakeSoft 5 1,877 Apr-09-2022, 07:45 AM
Last Post: DrakeSoft
  Not including a constructor __init__ in the class definition... bytecrunch 3 11,517 Sep-02-2021, 04:40 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020