Here are the examples of the python api sys.stderr taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
145 Examples
5
View Complete Implementation : test_function.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
def test_callback_returning_void(self):
ffi = FFI(backend=self.Backend())
for returnvalue in [None, 42]:
def cb():
return returnvalue
fptr = ffi.callback("void(*)(void)", cb)
old_stderr = sys.stderr
try:
sys.stderr = StringIO()
returned = fptr()
printed = sys.stderr.getvalue()
finally:
sys.stderr = old_stderr
astert returned is None
if returnvalue is None:
astert printed == ''
else:
astert "None" in printed
3
View Complete Implementation : testFlat.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
def testProcessNoncontiguous(self):
"Test Process function with non-contiguous array, which should raise an error"
print(self.typeStr, "... ", end=' ', file=sys.stderr)
process = Flat.__dict__[self.typeStr + "Process"]
pack_output = ''
for i in range(24):
pack_output += struct.pack(self.typeCode,i)
x = np.frombuffer(pack_output, dtype=self.typeCode)
x.shape = (2,3,4)
self.astertRaises(TypeError, process, x[:,:,0])
3
View Complete Implementation : testSuperTensor.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
def testLUSplit(self):
"Test luSplit function"
print(self.typeStr, "... ", file=sys.stderr)
luSplit = SuperTensor.__dict__[self.typeStr + "LUSplit"]
supertensor = np.ones(2*2*2*2, dtype=self.typeCode).reshape((2, 2, 2, 2))
answer_upper = [[[[0, 0], [0, 1]], [[0, 1], [1, 1]]], [[[0, 1], [1, 1]], [[1, 1], [1, 1]]]]
answer_lower = [[[[1, 1], [1, 0]], [[1, 0], [0, 0]]], [[[1, 0], [0, 0]], [[0, 0], [0, 0]]]]
lower, upper = luSplit(supertensor)
self.astertEquals((lower == answer_lower).all(), True)
self.astertEquals((upper == answer_upper).all(), True)
3
View Complete Implementation : gh_api.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
def get_pull_request(project, num, auth=False):
"""get pull request info by number
"""
url = "https://api.github.com/repos/{project}/pulls/{num}".format(project=project, num=num)
if auth:
header = make_auth_header()
else:
header = None
print("fetching %s" % url, file=sys.stderr)
response = requests.get(url, headers=header)
response.raise_for_status()
return json.loads(response.text, object_hook=Obj)
3
View Complete Implementation : gh_api.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
def get_paged_request(url, headers=None, **params):
"""get a full list, handling APIv3's paging"""
results = []
params.setdefault("per_page", 100)
while True:
if '?' in url:
params = None
print("fetching %s" % url, file=sys.stderr)
else:
print("fetching %s with %s" % (url, params), file=sys.stderr)
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
results.extend(response.json())
if 'next' in response.links:
url = response.links['next']['url']
else:
break
return results
3
View Complete Implementation : testFlat.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
def testProcess3DTranspose(self):
"Test Process function 3D array, FORTRAN order"
print(self.typeStr, "... ", end=' ', file=sys.stderr)
process = Flat.__dict__[self.typeStr + "Process"]
pack_output = ''
for i in range(24):
pack_output += struct.pack(self.typeCode,i)
x = np.frombuffer(pack_output, dtype=self.typeCode)
x.shape = (2,3,4)
y = x.copy()
process(y.T)
self.astertEquals(np.all((x.T+1)==y.T),True)
3
View Complete Implementation : testTensor.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
def testLUSplit(self):
"Test luSplit function"
print(self.typeStr, "... ", end=' ', file=sys.stderr)
luSplit = Tensor.__dict__[self.typeStr + "LUSplit"]
lower, upper = luSplit([[[1, 1], [1, 1]],
[[1, 1], [1, 1]]])
self.astertEquals((lower == [[[1, 1], [1, 0]],
[[1, 0], [0, 0]]]).all(), True)
self.astertEquals((upper == [[[0, 0], [0, 1]],
[[0, 1], [1, 1]]]).all(), True)
3
View Complete Implementation : gh_api.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
def get_paged_request(url, headers=None, **params):
"""get a full list, handling APIv3's paging"""
results = []
params.setdefault("per_page", 100)
while True:
if '?' in url:
params = None
print("fetching %s" % url, file=sys.stderr)
else:
print("fetching %s with %s" % (url, params), file=sys.stderr)
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
results.extend(response.json())
if 'next' in response.links:
url = response.links['next']['url']
else:
break
return results
3
View Complete Implementation : pindent.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
def make_backup(filename):
import os, os.path
backup = filename + '~'
if os.path.lexists(backup):
try:
os.remove(backup)
except OSError:
print("Can't remove backup %r" % (backup,), file=sys.stderr)
# end try
# end if
try:
os.rename(filename, backup)
except OSError:
print("Can't rename %r to %r" % (filename, backup), file=sys.stderr)
3
View Complete Implementation : gh_api.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
Copyright BSD 3-Clause "New" or "Revised" License
Author : holzschu
def get_pull_request(project, num, auth=False):
"""get pull request info by number
"""
url = "https://api.github.com/repos/{project}/pulls/{num}".format(project=project, num=num)
if auth:
header = make_auth_header()
else:
header = None
print("fetching %s" % url, file=sys.stderr)
response = requests.get(url, headers=header)
response.raise_for_status()
return json.loads(response.text, object_hook=Obj)