def test_on_peu_voter_entre_deux_foo(self): foo1 = Foo('machin') foo2 = Foo('truc') foo1.a_vaincu(foo2) self.assertEqual(1500. + K / 2, foo1.score) self.assertEqual(1500. - K / 2, foo2.score)
def get_objs(): obj1 = foo.Foo() obj2 = Foo() obj3 = Foo(attr='overridden') return ((obj1.get(), obj1.get_class_attr()), (obj2.get(), obj2.get_class_attr()), (obj3.get(), obj3.get_class_attr()))
def test_on_peut_avoir_deux_foo_aleatoires(self): foo1 = Foo('ciblout') foo2 = Foo('remram') Foo.ajouter(foo1) Foo.ajouter(foo2) foos = Foo.get_two_foos() self.assertEqual(len(foos), 2) self.assertIn(foo1, foos) self.assertIn(foo2, foos)
def test_on_peut_classer(self): foo1 = Foo('ciblout') foo2 = Foo('remram') foo3 = Foo('remram') Foo.ajouter(foo1) Foo.ajouter(foo2) Foo.ajouter(foo3) foo1.a_vaincu(foo2) foos = Foo.get_sorted_list(2) self.assertEqual(len(foos), 2) self.assertEqual(foo1, foos[0]) self.assertEqual(foo3, foos[1])
def main(): logger.info('Entering main ...') logger.debug('This is a demo for logging.') f = Foo() f.do_foo(42) bar.bar() logger.info('Leaving main ...')
def test_foo(): from foo import Foo f = Foo(10) assert f.n == 10 f.incr() assert f.n == 11
def test_transaction(self): # test commit with TestDatabase.db.transaction(): TestDatabase.db.upsert(Bar(101, 180, 33.5, 'A')) TestDatabase.db.upsert(Bar(102, 270, 50.33, 'B')) bars = TestDatabase.db.select(Bar()) self.assertEqual(len(bars), 4) # test rollback on exception with TestDatabase.db.transaction(), \ self.assertRaises(DatabaseIntegrityError) as cm: TestDatabase.db.upsert(Foo('a new foo', )) self.assertEqual(cm.exception.args[0], 'NOT NULL constraint failed: foo.desc') self.assertEqual(len(bars), 4) # test a forced rollback with TestDatabase.db.transaction() as t: TestDatabase.db.upsert( Bar(104, 355, 99.99, 'D')) t.fail() bars = TestDatabase.db.select(Bar()) self.assertEqual(len(bars), 4) # restore table to pre-test state with TestDatabase.db.transaction(): TestDatabase.db.delete(Bar(101)) TestDatabase.db.delete(Bar(102)) bars = TestDatabase.db.select(Bar()) self.assertEqual(len(bars), 2)
def require_file_module(): f = Foo() return f.bar()
def test_external_module(): return Foo().go_google()
def __init__(self): self.__foo = Foo(42, 'Fish', [0, 1, 2, 3])
def main(): o = Foo('alloha') print(o.getName())
"""test.py - demo of using a c++ class from within Python""" from foo import Foo # We'll create a Foo object with a value of 5... f = Foo(5) # Calling f.bar() will print a message including the value... print('f=Foo(5)') print('f.bar() = {}'.format(f.bar())) # Now we'll use foobar to add a value to that stored in our Foo object, f print("f.foobar(7) = {}".format(f.foobar(7))) # Now we'll do the same thing - but this time demonstrate that it's a normal # Python integer... x = f.foobar(2) print("Type of x; where x = f.foobar(2) is {}".format(type(x)))
def test_foo(self): foo_instance = Foo() self.assertEqual(foo_instance.foo(x=32), 64)
def test_on_peut_ajouter_des_foos(self): foo = Foo('ciblout') Foo.ajouter(foo) self.assertIn(foo, foo.get_liste())
def __init__(self): self.buf = [0, 0, 0, 0, 0] self.foo = Foo(self.buf) self.bar = Bar(self.buf)
def get_indirect(): return foo.get_foo() + ' and bar' def get_direct(): return get_foo() + ' and bar' def get_internal(): from foo import get_foo return get_foo() + ' and bar' glob_obj1 = foo.Foo() glob_obj2 = Foo() glob_obj3 = Foo(attr='overridden') def get_glob_objs(): return ((glob_obj1.get(), glob_obj1.get_class_attr()), (glob_obj2.get(), glob_obj2.get_class_attr()), (glob_obj3.get(), glob_obj3.get_class_attr())) def get_objs(): obj1 = foo.Foo() obj2 = Foo() obj3 = Foo(attr='overridden') return ((obj1.get(), obj1.get_class_attr()),
def test_foo_get(self): foo_instance = Foo() self.assertIsInstance(foo_instance.foo_get(), foo.Bar)
def test_on_peut_renvoyer_du_hteumeuleu(self): foo = Foo('superFooMash') self.assertIsInstance(foo.__html__(), str)
from foo import Foo print(Foo().scope)
def test_clear(self): foo = Foo('ciclout') Foo.ajouter(foo) Foo.clear() self.assertEqual(Foo.get_liste(), [])
def main(): foo = [Foo(luca.status()), Foo(dishroom()), Foo(huh()), Foo(sports())] for f in foo: print(f.say())
def test_cas_foireux_pour_deux_foos(self): self.assertRaises(Foo.NotEnoughFoos, Foo.get_two_foos) Foo.ajouter(Foo('chose')) self.assertRaises(Foo.NotEnoughFoos, Foo.get_two_foos)
from flask import Flask, render_template, request, redirect from foo import Foo app = Flask("Meta foomash") @app.route('/') def index(): foos = Foo.get_two_foos() return render_template('index.html', foos=foos, list_foos=Foo.get_liste()) @app.route('/vote', methods=["GET"]) def vote(): foo = Foo.get_by_name(request.args['name']) other = Foo.get_by_name(request.args['other']) foo.a_vaincu(other) return redirect("/") if __name__ == "__main__": Foo.ajouter(Foo('ciblout')) Foo.ajouter(Foo('remram')) Foo.ajouter(Foo('lily')) app.debug = True app.run()
def test_get_by_name(self): Foo.ajouter(Foo('ciblout')) Foo.ajouter(Foo('remram')) Foo.ajouter(Foo('lily')) foo = Foo.get_by_name('remram') self.assertEqual('remram', foo.name)
def require_sub_file_module(): f = Foo() return f.yum()
#!/usr/bin/python # -*- coding: utf-8 -*- """ -------------------------------------------------------------- describe: base_info: __version__ = "v.10" __author__ = "mingliang.gao" __time__ = "2020/5/23 5:07 PM" __mail__ = "*****@*****.**" -------------------------------------------------------------- """ # ------------------------------------------------------------ # usage: /usr/bin/python __init__.py.py # ------------------------------------------------------------ from foo import Foo foo_entry_point = Foo().entry_point()
def what_is_love(): f = Foo() return f.what_is_love(my_global_var)
def test_bar(self): foo_instance = Foo() self.assertEquals(foo_instance.bar(x=32), 64)
def test_foreign_key(self): with TestDatabase.db.transaction(), \ self.assertRaises(DatabaseIntegrityError) as cm: # bar id 999 should not exist TestDatabase.db.upsert(Foo('my foo', 'a new foo', 999)) self.assertEqual('FOREIGN KEY constraint failed', cm.exception.args[0])