Exemple #1
0
# file: example.py

import example

# Call our gcd() function

x = 42
y = 105
g = example.gcd(x, y)
print "The gcd of %d and %d is %d" % (x, y, g)

# Manipulate the Foo global variable

# Output its current value
print "Foo = ", example.cvar.Foo

# Change its value
example.cvar.Foo = 3.1415926

# See if the change took effect
print "Foo = ", example.cvar.Foo
def test_gcd_same_number():
  assert gcd(42, 42) == 42
def test_gcd_prime():
  assert gcd(11, 23) == 1
def test_gcd_second_arg_zero():
  assert gcd(42, 0) == 42
def test_gcd_first_arg_zero():
  assert gcd(0, 42) == 42
def test_gcd_non_prime():
  assert gcd(56, 42) == 14
Exemple #7
0
cppfiles = '.cppfiles'
pyfiles = '.pyfiles'
os.makedirs(cppfiles, exist_ok=True)
os.makedirs(pyfiles, exist_ok=True)

kw = dict(target=target, cppfiles=cppfiles, pyfiles=pyfiles)
out, err = subprocess.Popen(['swig -c++ -python -outdir {pyfiles} -o {cppfiles}/{target}_wrap.cpp {target}.i'.format(**kw)], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate()
# Call our gcd() function

print('stdout:[\n{}\n]'.format(out.decode())) if out else None
print('stderr:[\n{}\n]'.format(err.decode())) if err else None

import example


x = 42
y = 105
g = example.gcd(x, y)
print("The gcd of %d and %d is %d" % (x, y, g))

# Manipulate the Foo global variable

# Output its current value
print("Foo = ", example.cvar.Foo)

# Change its value
example.cvar.Foo = 3.1415926

# See if the change took effect
print("Foo = ", example.cvar.Foo)
Exemple #8
0
 def test_gcd(self):
     self.assertEquals(example.gcd(2, 8), 2)