Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

testing - How do I test Python with test files and expected output files

I have a Python script.
A particular method takes a text file and may creates0-3 files.
I have sample text files, and the expected output files for each.

How would I set up this script for testing?
I use unittest for testing functions that do not have file i/o currently.

  • SampleInputFile1 -> expect 0 files generated.
  • SampleInputFile2 -> expect 1 files generated with specific output.
  • SampleInputFile3 -> expect 3 files generated, each with specific output.

I want to ensure all three sample files, expected files are generated with expected content. Testing script question

question from:https://stackoverflow.com/questions/65906695/how-do-i-test-python-with-test-files-and-expected-output-files

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

maybe I dont understand the question but you use a program to divide a text into different subtexts?

Why dont you use train_test_split from sklearn to get the test and training files,

sklearn.model_selection.train_test_split(*arrays, test_size=None, train_size=None, random_state=None, shuffle=True, stratify=None)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...