def paintGL(self): """Called by QtGL when redrawing is needed. For every redraw, color & depth butter are cleared, view projection are reset, view location & orientation are also reset. """ if not self.initialised: return c = self.backgroundColor glClearColor(c[0], c[1], c[2], 0.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) self.aspect = (self.width + 0.0) / (self.height + 0.0) self.vdist = 6.0 * self.scale self._setup_projection() glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslatef(0.0, 0.0, -self.vdist) #q = self.quat #glRotatef(q.angle*180.0/pi, q.x, q.y, q.z) glTranslatef(self.pov[0], self.pov[1], self.pov[2]) #self.drawModel() foo.foo()
def __paintEvent(self, e): """Draw a colorful collection of lines and circles. """ foo.foo() if False: print 'paintEvent', sys.stdout.flush() if False: # Here is how to draw stuff using PyQt p = QPainter() size = self.frame1.size() w, h = size.width(), size.height() p.begin(self.frame1) p.eraseRect(0, 0, w, h) for i in range(100): color = random.choice(self.COLOR_CHOICES) p.setPen(QPen(color)) p.setBrush(QBrush(color)) x1 = w * random.random() y1 = h * random.random() if random.random() < 0.5: x2 = w * random.random() y2 = h * random.random() p.drawLine(x1, y1, x2, y2) else: x2 = 0.05 * w * random.random() y2 = x2 p.drawEllipse(x1, y1, x2, y2) p.flush() p.end()
def paintGL(self): """Called by QtGL when redrawing is needed. For every redraw, color & depth butter are cleared, view projection are reset, view location & orientation are also reset. """ if not self.initialised: return c = self.backgroundColor glClearColor(c[0], c[1], c[2], 0.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) self.aspect = (self.width + 0.0)/(self.height + 0.0) self.vdist = 6.0 * self.scale self._setup_projection() glMatrixMode(GL_MODELVIEW) glLoadIdentity() glTranslatef(0.0, 0.0, -self.vdist) #q = self.quat #glRotatef(q.angle*180.0/pi, q.x, q.y, q.z) glTranslatef(self.pov[0], self.pov[1], self.pov[2]) #self.drawModel() foo.foo()
def task_do(): if request.method == 'POST': if request.form['submit'] == 'start_a_long_process': print 'long task running' foo.foo(1,1000000) # out=foo.foo(1,1000) # print out return render_template('task_complete.html')
def test_foo(): import sys from foo import foo from io import StringIO saved_stdout = sys.stdout try: out = StringIO() sys.stdout = out foo() output = out.getvalue().strip() assert output == 'hello world!' finally: sys.stdout = saved_stdout
def fn(): foo() print('im bar')
def main1(): foo()
import os import boto3 from bar import bar from bar.baz import baz from foo import foo _ = boto3 if __name__ == "__main__": INIT_FILENAME = "__init__.py" dirname = os.path.dirname(os.path.abspath(__file__)) assert bar() == os.path.join(dirname, "bar", INIT_FILENAME) assert baz() == os.path.join(dirname, "bar", "baz", INIT_FILENAME) assert foo() == os.path.join(dirname, "foo", INIT_FILENAME)
#!/usr/bin/env python import foo import foo.bar foo.foo() foo.bar.bar()
def bar(): global a print(a) foo() print(a) test()
import foo x = foo.foo(10, 2) print(x)
def test_foo_str(): '''Test foo string output.''' assert foo('dummy') == 'foo'
def test_foo(self): self.assertEqual(1, foo.foo())
def foo2(self): def bar_stub(): return 'baz' foo.bar = bar_stub eq_(foo.foo(), 'foobaz')
# this file is for unit testing relative imports from foo import foo x = foo()
import foo print foo.foo(3) print foo.bar(3)
import foo foo.foo("foo", 20)
def test_foo(): assert foo() == 'foo'
def main(argv=None): print "in main function" print __name__ foo.foo()
def testFoo(self): self.assertEquals(foo.foo(), 6, 'foo() == 6')
#/usr/bin/python3 # #module import foo import sys print("=" * 100) print("6.1.1 Module") print("=" * 100) if __name__ == "__main__": foo.foo(sys.argv[1]) #python .\lesson\6\6.1\6.1.1.py "This is argument" #This is foo foo function, input value n= This is argument
def hello_world(): foo() print "hello world!"
def goo(): """ call foo """ a = foo.foo(b=1) return a
def test_foo(): assert foo(5) == 6
from foo import foo print(foo())
def test_bar_is_called_in_foo(mock): assert foo() == 42 assert mock.called is True
def foo(self): with patch('foo.bar') as mock: mock.return_value = "baz" eq_(foo.foo(), 'foobaz')
def bar(): return foo()
def test_foo(): assert foo() == "foo"
#/usr/bin/python3 # #module print("=" * 100) print("6.1 Module") print("=" * 100) import foo foo.foo(200) print(foo.__name__) #import other way #or from foo import * will import all functions except the function which name start with _ #from foo import foo from foo import * foo(50) #can't access _xxx function #_test() #foo._test() #or rename from foo import foo as foo1 foo1('This is foo1') #if using interative mode, the module only import once, or use importlib.reload(modulename)。
import foo foo.foo("foo", "20")
def test_foo(self): doc = foo() self.assertRegex(doc, 'Widgets')
import foo myfoo = foo.foo() myfoo.hello()
def test_1_pawn(self): bar = [] self.assertEquals(foo(bar), 0)