Ejemplo n.º 1
0
#https://docs.python.org/3/py-modindex.html

"Modules"
#A file containing a set of functions you want to include in your application.
#packages are collection of modules
"""We can define our most used functions in a module and import it, instead of copying their definitions 
into different programs."""

import Example  #we want to create example.py module in local machine
Example.add(4, 5)

'Or'

from Example import add
add(22, 2)

import math  #import statement access the definitions of it
print("The value of pi is", math.pi)

int(math.sqrt(9))

#renaming

import math as m
m.pi

#We can import specific names from a module without importing the module as a whole.
from math import pi
math.pi

#import all by *
Ejemplo n.º 2
0
 def testAddPositiv(self):
     self.assertEqual(3, ex.add(1, 2))
Ejemplo n.º 3
0
 def testAddWrongInput(self):
     self.assertRaises(TypeError, ex.add("a", "b"))
Ejemplo n.º 4
0
 def mockExample(self, mock1, mock2):
     self.assertEqual(True, ex.returnFalse())
     self.assertEqual(0, ex.add(100, 100))
Ejemplo n.º 5
0
 def testAddNegative(self):
     self.assertEqual(-8, ex.add(-3, -5))