Lecture 7 - Python Modules and Testing

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What happens to a module's __name__ variable when: 1) It is run directly in the console 2) You click the run button 3) When it is imported?

1) __name__ is set to __main__ 2) __name__ is set to __main__ 3) __name__ is set to __variable__

How would you specify some code to run only when a module runs as the main program?

>>> if __name__ == "__main__":

What are the two ways of important a module?

>>> import module_name >>> import module_name as local_name

How would you call a function from a module that has just been imported?

>>> module_name.function_name(argument) e.g. import math var = 2.95 math.tranc(var)

What is a module? What is the name of a module?

A collection of (usually related) functions and data (variables) grouped in a single file with a .py extension. Technically, every python file (with extension .py) is a module. The name of the module is the file name. (without the .py).

What is test-driven development?

A style of programming in which one writes the test cases prior to writing the code for a unit.

What is a doctest?

A very simple python module used in testing. It searches the doc string for lines that start with >>>, executes them, and compares the output with the next line which is supposed to have the expected result.

What is alpha, beta, and installation testing?

Alpha -> Testing done by developers Beta -> Testing done by selected users Installation -> Testing done at the final site

How does Python find the files that it needs to import?

It first looks in its default directories, then the current directory (the directory that contains the last program that was executed).

What happens to a module after it is imported?

Python creates a variable with the module name (original or local, if defined), which references that module. Then, Python executes the module.

What happens when a module is important again in the same session?

Python does not load it again.

What is black-box testing?

The type of unit testing that is usually performed in test-driven development. It includes the following test cases: Typical cases -> These use typical values for the inputs Boundary cases -> These use boundary values for the inputs (values that are the smallest or largest allowable values for the unit's inputs) Simplest interesting cases -> These have input values that are close to the boundary values

What is unit testing? What is a test case?

Unit testing consists of a set of test cases for a unit of code. A test case consists of the input values and the expected output.


Kaugnay na mga set ng pag-aaral

"Lake Titicaca" by Miguel Asturias

View Set

Unit 1: The difference between empathy and sympathy

View Set

Pathophysiology Chapter 46 AKI & ESRD

View Set

8) Chapter 62: Care of Patients with Problems of the Biliary System and Pancreas

View Set

Political Theory Philosophy Test 2

View Set

Clinic Theory Test Chapter 33-38

View Set