Dew is a hobby of gardening testers, familiar with Python, reducing a lot of repetitive work. Pull it off. This two-month study concludes:
Basic
Grammar, data structure and so on the manual is enough, the use of the time will not be checked again, I believe only you can not think of Python does not support (here ignore the old bull).
file
Well, as a test, at first the most need to use Python file operation, a variety of read and write files, analysis data god horse. The need to use here is the Python file operation, and the use of various data structures, such as list,dict, and so on, as for the background data generated files, mostly JSON, Excel, Cpickle, these have ready-made library support.
For example, the use of JSON
Import JSON
#data获取到的是一个dict或者list结构的数据
data = json.load (open (filename, ' r '))
#将dict dump into a file that is stored in JSON format
Json.dump ({' X ': 1, ' Y ': 2}, open (filename, ' W '))
Other similar:
Exception Handling
In the case of file read-write or data analysis, often due to various reasons the program does not work properly, for example, the JSON file may be generated by other languages, NULL data is NULL, but there is no null in Python, only ", this time the data analysis will be abnormal, but in most cases, The exception of one or more of our data does not affect our results, so we need to capture these exceptions.
Try
Except Exception:
Can help you skip these exceptions, even if you need to have a log to record these exceptions, without affecting the results but may need to know what anomalies have occurred, the Dewdrop used the logging module to generate Log,python's log module has many kinds, ^_^ The function is not strong, it doesn't matter, suffice it.
These are only known to the program is possible to deal with the exception, but often, the most headache is the program in some unknown anomalies, causing the program crashes, or even crash without leaving a trace, well, dew on their own computer ran a file parsing program, ran 24h+, suddenly collapsed,, cried, Fortunately, at the end of the various methods to find the location of the crash, and then change the code to run, after the change will not be afraid of its collapse ^_^.
The method used is: Atexit. Usage:
Import @atexit. Register
Def atexit_fun ():
##
Do_my_work ()
Do a good job before the program crashes to prevent ^_^ from being caught off guard.
Resource Allocation
Dew of this file analysis program, the reason why ran so long, the beginning dew does not know where the bottleneck, but through the profile tool, it is easy to see the program run-time resource allocation (well, here to say, the analysis of the allocation of resources only with a small number of data can be, do not need to run a day and night). As for the specific use of the profile, Baidu Oh ^_^ yourself.
In some cases, multithreading can improve the efficiency of a program's execution. Python comes with the thread library, but beware of thread safety Oh, Python's native data structures are not thread-safe and need to be used with Thread.lock. Here Python threading.thread Dewdrops need to remind the children of shoes, Threading.thread rewrite the Run () method, but the transfer thread with the start () method, anyway I was guilty of 2 =o=
These are the skills that will be used as a test development, and the following are some of the skills the testers need:
Unit Test
Here Dewdrop with UnitTest, there is a library called coverage, is to do code coverage statistics test, the specific use of Baidu oh ^_^, forgive me ~ ~
testing, different projects or functions require us to install a different version of the library, if on a machine has been doing so, estimated to be crazy, Dew recommended virtualenv, a virtual Python environment, the library installed in the virtual environment will not affect the local, virtual environment can be multiple, Delete the virtual environment after use.
Two months of study, that's all. ^_^, Dew for the first time to write blog, help to Praise Oh, in addition, the wrong place please correct me ^_^ ~ ~
Two months of learning python nonsense