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
  Not including a constructor __init__ in the class definition... bytecrunch 3 457 Sep-02-2021, 04:40 AM
Last Post: deanhystad
  getting the length of a file in a loop sgcgrif33 1 414 Aug-23-2021, 05:11 PM
Last Post: deanhystad
  How to test and import a model form computer to test accuracy using Sklearn library Anldra12 6 909 Jul-03-2021, 10:07 AM
Last Post: Anldra12
  How to make python run other file? Adrian_L 4 832 Apr-06-2021, 06:39 PM
Last Post: ndc85430
  Something wrong with the quotation mark in dictionary definition Mark17 1 774 Jan-29-2021, 03:34 PM
Last Post: buran
  Is there anyway to make a .py file into a .exe file? Oshadha 2 961 Jan-13-2021, 04:58 AM
Last Post: Oshadha
  xml file creation from an XML file template and data from an excel file naji_python 1 764 Dec-21-2020, 03:24 PM
Last Post: Gribouillis
  Writing unit test results into a text file ateestructural 3 1,315 Nov-15-2020, 05:41 PM
Last Post: ateestructural
  want to make auto login with data R3born 3 1,010 Sep-11-2020, 07:06 PM
Last Post: R3born
  saving data from text file to CSV file in python having delimiter as space K11 1 881 Sep-11-2020, 06:28 AM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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