def run():
    'Tests the functionality of the extension.'

    import spam

    # spam should have a "system" function...try it out
    if spam.system('echo test') != 0 or spam.system('this_command_should_cause_an_error') != 1:
        raise AssertionError('test module did not function correctly')

    # unload
    del sys.modules['spam']

    print
    print 'Success!'
    print
Example #2
0
def multiply(a,b):
	print("Will compute", a, "times", b)
	c = 0
	for i in range(0, a):
		c = c + b

	
	spam.system('dir')
	unicStr1 = "This is Python world! 한글 시도? 日本語はどうだ?"
	unicStr2 = "日本語はどうだ?두번째 시도?"
	print('Python side 1:', unicStr1)
	print('Python side 2:', unicStr2)
	
	return c
	
Example #3
0
def run():
    'Tests the functionality of the extension.'

    import spam

    # spam should have a "system" function...try it out
    if spam.system('echo test') != 0 or spam.system(
            'this_command_should_cause_an_error') != 1:
        raise AssertionError('test module did not function correctly')

    # unload
    del sys.modules['spam']

    print
    print 'Success!'
    print
Example #4
0
def test_spam():
    import platform

    print("About to import spam")
    sys.stdout.flush()
    import spam

    if "This is an example spam doc." not in spam.__doc__:
        raise Exception("spam.__doc__ does not contain the expected text")

    cmd = {
        "Windows": "dir",
    }.get(platform.system(), "ls")
    print("About to run spam.system(\"{}\")".format(cmd))
    sys.stdout.flush()

    spam.system(cmd)
Example #5
0
 def test_spam(self):
     print(dir(sp))
     sp.system("ls -l")
Example #6
0
 def test_command_with_invalid_args(self):
     status = spam.system("ls --unrecognized-option")
     self.assertEqual(status, 2)
Example #7
0
 def test_wrong_arg_type(self):
     with self.assertRaises(TypeError):
         spam.system(0)
Example #8
0
#usr/bin/python  
#filenam : test.py  
import spam  
spam.system("dir")  
Example #9
0
 def test_command(self):
     status = spam.system("ls")
     self.assertEqual(status, 0)
Example #10
0
 def test_system(self):
     self.assertEqual(0, spam.system('python -c "exit(0)"'))
     self.assertNotEqual(0, spam.system('python -c "exit(1)"'))
Example #11
0
 def test_it_works(self) -> None:
     p = spam.system('ls -la')
     assert p == 0  # exit code
import spam

assert spam.system('date') == 0
assert spam.system('/bin/false') > 0
try:
    spam.system('does-not-exist')
except spam.error as e:
    assert str(e) == 'System command failed'

Example #13
0
'''
:Author: Arthur Goldberg <*****@*****.**>
:Date: 2017-04-06
:Copyright: 2017-2018, Karr Lab
:License: MIT
'''
# example program using example spam module

# TODO(Arthur): cover after MVP wc_sim done

import spam  # pragma: no cover

for cmd in ["ls -l", "date", "no_such_command", 7, None,
            'kill']:  # pragma: no cover
    try:
        status = spam.system(cmd)
        print("'{}' returns: {}".format(cmd, status))
    except Exception as e:
        print("Exception: '{}'".format(str(e)))

print(spam.nothing())  # pragma: no cover
Example #14
0
import spam

spam.system("ls -la")
Example #15
0
import spam

print(spam.system('ls -l'))
Example #16
0
import spam

spam.system('dir')
Example #17
0
import spam
x = spam.system("hello world!")
print x
Example #18
0
#!/usr/bin/env python3
import spam

print()
status = spam.system("ls -l | wc")
print("status: ", status)

print()
print('Expect spam.SpamError')
try:
    status = spam.check_system("false")
    print("status: ", status)
except spam.SpamError as ex:
    print(' ', ex)
    print('  ignored')

print()
s = spam.Spam("Real brand of SPAM")
s.print()
print(s)

print()
n1 = spam.Noddy1()
print(n1)

print()
n2 = spam.Noddy2(first="Mike", last="Bentley")
print(n2)
print("Name: ", n2.name())

print()
Example #19
0
 def testSystem(self):
   import spam
   res = spam.system("ls -l")
   if not res:
     self.Fail("system returned falsy value: %s" % (res))
Example #20
0
# spam_test.py

import spam

spam.system("sha1sum ../../data/Hello.txt")
spam.sha1_file("../../data/Hello.txt")

Example #21
0
#!/usr/bin/env python3

# Import the Python documentation Fibonacci module
import pydoc_fibonacci as fibonacci

# Import the Python documentation Spam module
import spam

# Test Fibonacci sequence to 100
fibonacci.fib(100)

# Test Fibonacci sequence (list return) to 100
print(fibonacci.fib2(100))

# Hello spam module
print(spam.system('echo hello spam!'))

# Test the Spam module by executing "ls -l"
print(spam.system('ls -l'))
Example #22
0
import spam
spam.system("ls -l")
spam.system("ls")
Example #23
0
def timeme(method):
    def wrapper(*args, **kw):
        startTime = int(round(time.time() * 1000))
        result = method(*args, **kw)
        endTime = int(round(time.time() * 1000))

        print(endTime - startTime, 'ms')
        return result

    return wrapper


spam.greet('cassie')

spam.system('ls')

print spam.strlen("1234")


def python_fb(num):
    result = []
    first = 0
    second = 1
    for i in xrange(num):
        if i <= 1:
            next = i
        else:
            next = first + second
            first = second
            second = next
Example #24
0
 def test_true(self):
     status = spam.system("true")
     self.assertEqual(status, 0)
Example #25
0
import spam

spam.system("ls -a")
Example #26
0
    def __init__(self,im_axis,re_axis,im_data,kernel_mode='',model=None,stdev=None,beta=None,**kwargs):
        self.kernel_mode = kernel_mode
        self.im_axis = im_axis
        self.re_axis = re_axis
        self.im_data = im_data
        self.nw = self.re_axis.shape[0]
        self.wmin = self.re_axis[0]
        self.wmax = self.re_axis[-1]
        self.dw = np.diff(np.concatenate(([self.wmin],(self.re_axis[1:]+self.re_axis[:-1])/2.,[self.wmax])))
        self.model = model # the model should be normalized by the user himself

        if (self.kernel_mode == 'freq_bosonic'):
            self.var = stdev**2
            self.E = 1./self.var
            self.niw = self.im_axis.shape[0]
            self.kernel = (self.re_axis**2)[None,:] / ((self.re_axis**2)[None,:] + (self.im_axis**2)[:,None])
            self.kernel[0,0] = 1. # analytically with de l'Hospital
        elif (self.kernel_mode == 'time_bosonic'):
            self.var = stdev**2
            self.E = 1. / self.var
            self.niw = self.im_axis.shape[0]
            self.kernel = 0.5 * self.re_axis[None,:] * (
                np.exp(-self.re_axis[None,:]*self.im_axis[:,None])
                + np.exp(-self.re_axis[None,:]*(1. - self.im_axis[:,None]))) / (
                    1. - np.exp(-self.re_axis[None,:]))
            self.kernel[:, 0] = 1. # analytically with de l'Hospital
        elif (self.kernel_mode == 'freq_fermionic'):
            self.var = np.concatenate((stdev**2, stdev**2))
            self.E = 1. / self.var
            self.niw = 2 * self.im_axis.shape[0]
            self.kernel = np.zeros((self.niw, self.nw)) # fermionic Matsubara GF is complex
            self.kernel[:self.niw/2, :] = -self.re_axis[None,:] / ((self.re_axis**2)[None,:] + (self.im_axis**2)[:,None])
            self.kernel[self.niw/2:, :] = -self.im_axis[:,None] / ((self.re_axis**2)[None,:] + (self.im_axis**2)[:,None])
        elif (self.kernel_mode == 'time_fermionic'):
            self.var = stdev**2
            self.E = 1. / self.var
            self.niw = self.im_axis.shape[0]
            self.kernel = (np.exp(-self.im_axis[:,None] * self.re_axis[None,:]) /
                               (1.+np.exp(-self.re_axis[None,:])))
        elif (self.kernel_mode == 'freq_fermionic_phsym'): # in this case, the data must be purely real (the imaginary part!)
            print ('Warning: phsym kernels do not give good results in this implementation. ')
            self.var = stdev**2
            self.E = 1. / self.var
            self.niw = self.im_axis.shape[0]
            self.kernel = -2. * self.im_axis[:,None] / ((self.im_axis**2)[:,None] + (self.re_axis**2)[None,:])
        elif (self.kernel_mode == 'time_fermionic_phsym'):
            print ('Warning: phsym kernels do not give good results in this implementation. ')
            self.var = stdev**2
            self.E = 1. / self.var
            self.niw = self.im_axis.shape[0]
            self.kernel = (np.cosh(self.im_axis[:,None] * self.re_axis[None,:])
                          + np.cosh((1. - self.im_axis[:,None]) *
                                        self.re_axis[None,:])) / (1. + np.cosh(self.re_axis[None,:]))
        else:
            print ('Unknown kernel')
            sys.exit()

        U, S, Vt = np.linalg.svd(self.kernel, full_matrices=False)

        self.n_sv = np.arange(min(self.nw,self.niw))[S>1e-10][-1] # number of singular values larger than 1e-10

        self.U_svd = np.array(U[:, :self.n_sv], dtype=np.float64,order='C')
        self.V_svd = np.array(Vt[:self.n_sv, :].T, dtype=np.float64,order='C') # numpy.svd returns V.T
        self.Xi_svd = S[:self.n_sv]

        print ('spectral points:', self.nw)
        print ('data points on imaginary axis:', self.niw)
        print ('significant singular values:', self.n_sv)
        print ('U', self.U_svd.shape)
        print ('V', self.V_svd.shape)
        print ('Xi', self.Xi_svd.shape)

        #=============================================================================================
        # First, precompute as much as possible
        # The precomputation of W2 is done in C, this saves a lot of time!
        # The other precomputations need less loop, can stay in python for the moment.
        #=============================================================================================
        print  ('Precomputation of coefficient matrices')

        # allocate space
        self.W2 = np.zeros((self.n_sv, self.nw), order='C', dtype=np.float64)
        self.W3 = np.zeros((self.n_sv, self.n_sv, self.nw))
        self.d2chi2 = np.zeros((self.nw, self.nw))
        self.Evi = np.zeros((self.n_sv))

        # precompute matrices W_ml (W2),  W_mil (W3)
        spam.system(self.W2, self.E, self.U_svd, self.Xi_svd, self.V_svd, self.dw, self.model)
        #precomp.precompute_W2(self.W2, self.E, self.U_svd, self.Xi_svd, self.V_svd, self.dw, self.model)
        #self.W3 = self.W2[:, None, :]*(self.V_svd[None, :, :]).transpose((0, 2, 1))

        # precompute the evidence vector Evi_m
        #for m in xrange(self.n_sv):
        #    for k in xrange(self.niw):
        #        self.Evi[m]+=self.Xi_svd[m]*self.U_svd[k, m]*self.E[k]*self.im_data[k]

        # precompute curvature of likelihood function
        #precomp.precompute_d2chi2(self.d2chi2, self.kernel, self.dw, self.E)

        # some arrays that are used later...
        self.chi2arr = []
        self.specarr = []
        self.backarr = []
        self.entrarr = []
        self.alpharr = []
        self.uarr = []
        self.bayesConv = []
"""
Tests for integrating our own modules
"""
import spam
status = spam.system("df")
Example #28
0
import spam
spam.system('ls -l')
Example #29
0
import spam
status = spam.system("ls -l")
Example #30
0
#usr/bin/python
#filenam : test.py
import spam
spam.system("dir")
Example #31
0
 def test_false(self):
     status = spam.system("false")
     self.assertEqual(status, 1)
Example #32
0
import spam #expects a C-extension lib named spammodule.so

spam.system('ls -l')
Example #33
0
 def test_command_with_args(self):
     status = spam.system("ls -l")
     self.assertEqual(status, 0)
Example #34
0
File: test.py Project: gitpan/swig
import spam
print "Executing spam.system('ls') ... "
spam.system("ls")
Example #35
0
 def test_command_not_found(self):
     status = spam.system("command_not_found")
     self.assertEqual(status, 127)
Example #36
0
def main():
    ret = spam.system("ls -l")
    print(ret)
Example #37
0
import spam

spam.system("ls -l")
Example #38
0

import spam

print spam.system("ls -l")




Example #39
0
# import conv_util as cos_module_np
import numpy as np
# import pylab

x = np.arange(0, 2 * np.pi, 0.1)
print(x)
import spam
print(spam.system("ls -l"))
import convUtil
convUtil.c_ext_forward()
import cos_module_np
y = cos_module_np.cos_func_(x)
print(x,y)
import spam
spam.system("ls -l", 4)