Пример #1
0
def test_foo():

    from foo import Foo
    f = Foo(10)
    assert f.n == 10
    f.incr()
    assert f.n == 11
Пример #2
0
def sqlexec(script, checkExit=True):
    with io.open(scriptFile_getBackupInfo, "w") as file:
        file.write(script)

    sqlprc = Popen(sqlcmd.format(script=scriptFile_getBackupInfo), shell=True, stdout=PIPE, stderr=PIPE)
    sqlprc.wait()

    sqlprcExitCode = sqlprc.returncode
    sqlprcOutputValues = sqlprc.communicate()
    sqlprcStdout = sqlprcOutputValues[0]
    sqlprcStderr = sqlprcOutputValues[1]

    res = Foo()
    res.exitCode = sqlprc.returncode
    res.stdOut = sqlprcOutputValues[0]
    res.stdErr = sqlprcOutputValues[1]

    if checkExit:
        if res.exitCode != 0:
            print "sql script failed!"
            print "command:"
            print sqlcmd
            print "sql script:"
            print script
            print "exit code:"
            print res.exitCode
            print "stdout:"
            print res.stdOut
            print "stderr:"
            print res.stdErr
            sys.exit(1)

    return res
Пример #3
0
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 ...')
Пример #4
0
def test_foo():

    from foo import Foo
    f = Foo(10)
    assert f.n == 10
    f.incr()
    assert f.n == 11
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    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)
Пример #8
0
class Main():
    def __init__(self):

        self.buf = [0, 0, 0, 0, 0]
        self.foo = Foo(self.buf)
        self.bar = Bar(self.buf)

    def run(self):

        print(self.buf)
        self.foo.add_one()
        print(self.buf)
        self.foo.get_buf()
Пример #9
0
    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])
Пример #10
0
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()))
Пример #11
0
    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)
Пример #12
0
    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)
Пример #13
0
 def test_foo_get(self):
     foo_instance = Foo()
     self.assertIsInstance(foo_instance.foo_get(), foo.Bar)
Пример #14
0
 def test_clear(self):
     foo = Foo('ciclout')
     Foo.ajouter(foo)
     Foo.clear()
     self.assertEqual(Foo.get_liste(), [])
Пример #15
0
 def test_on_peut_ajouter_des_foos(self):
     foo = Foo('ciblout')
     Foo.ajouter(foo)
     self.assertIn(foo, foo.get_liste())
Пример #16
0
    def __init__(self):

        self.buf = [0, 0, 0, 0, 0]
        self.foo = Foo(self.buf)
        self.bar = Bar(self.buf)
Пример #17
0
import sys
sys.path.append('build')

from foo import Foo

foo = Foo()
print foo.a
foo.a = 1
print foo.a
Пример #18
0
def test_external_module():
	return Foo().go_google()
Пример #19
0
def require_sub_file_module():
	f = Foo()
	return f.yum()
Пример #20
0
def getBackupInfo(databaseName):
    getDbBackupscript = u"""
	declare @cmt varchar(200)
	set @cmt = ''

	declare @dbname varchar(250)
	set @dbname = '{database_name}'

	print @cmt+'database '+@dbname

	print @cmt+'full backup of '+@dbname
	declare @full_bs_id		numeric(38)
	declare @full_start		datetime
	declare @full_end		datetime
	declare @full_created	bit
	declare @full_lsn		numeric(38)
	declare @full_media_id	numeric(38)
	declare @full_media_file varchar(2000)
	declare @full_media_pos numeric(38)

	set @full_created = 0

	select top 1 
		@full_created = 1,
		@full_bs_id = backup_set_id,
		@full_start = backup_start_date,
		@full_end   = backup_finish_date,
		@full_lsn   = database_backup_lsn,
		@full_media_pos = position,
		@full_media_id = media_set_id,
		@full_media_file = (select b.physical_device_name from msdb.dbo.backupmediafamily b where b.media_set_id = bs.media_set_id)
	from msdb.dbo.backupset bs 
	where 
		bs.database_name = @dbname 
		and bs.type = 'D'
	order by bs.backup_start_date desc

	if @full_created = 1 begin
		print @cmt+'full backupset id:       '+cast(@full_bs_id as varchar)
		print @cmt+'full backupset started:  '+convert(varchar(200),@full_start,120) -- +cast(@full_start as varchar)
		print @cmt+'full backupset finished: '+convert(varchar(200),@full_end,120) -- +cast(@full_end as varchar)
		print @cmt+'full backupset db lsn:   '+cast(@full_lsn as varchar)
		print @cmt+'full backupset media id: '+cast(@full_media_id as varchar)
		print @cmt+'full media file:         '+@full_media_file
		print @cmt+'full media position:     '+cast(@full_media_pos as varchar)
		
		print @cmt+'diff backup of '+@dbname
		declare @diff_bs_id numeric(38)
		declare @diff_start datetime
		declare @diff_end   datetime
		declare @diff_created bit
		declare @diff_lsn   numeric(38)
		declare @diff_media_id	numeric(38)
		declare @diff_media_file varchar(2000)
		declare @diff_media_pos numeric(38)

		set @diff_created = 0

		select top 1 
			@diff_created = 1,
			@diff_bs_id = backup_set_id,
			@diff_start = backup_start_date,
			@diff_end   = backup_finish_date,
			@diff_lsn   = database_backup_lsn,
			@diff_media_pos = position,
			@diff_media_id = media_set_id,
			@diff_media_file = (select b.physical_device_name from msdb.dbo.backupmediafamily b where b.media_set_id = bs.media_set_id)
		from msdb.dbo.backupset bs 
		where 
			bs.database_name = @dbname 
			and bs.type = 'I'
			and bs.database_backup_lsn > @full_lsn
		order by bs.backup_start_date desc

		if @diff_created = 1 begin
			print @cmt+'diff backupset id:       '+cast(@diff_bs_id as varchar)
			print @cmt+'diff backupset started:  '+convert(varchar(200),@diff_start,120) -- +cast(@diff_start as varchar)
			print @cmt+'diff backupset finished: '+convert(varchar(200),@diff_end,120) -- +cast(@diff_end as varchar)
			print @cmt+'diff backupset db lsn:   '+cast(@diff_lsn as varchar)
			print @cmt+'diff backupset media id: '+cast(@diff_media_id as varchar)
			print @cmt+'diff media file:         '+@diff_media_file
			print @cmt+'diff media position:     '+cast(@diff_media_pos as varchar)
		end
	end else begin
		print @cmt+'! full backup of '+@dbname+' not exists'
	end

	go
	""".format(
        database_name=databaseName
    )

    res = sqlexec(getDbBackupscript)
    sqlprcStdoutLines = re.split("\r\n|\n|\r", res.stdOut)

    res = Foo()
    full = Foo()
    fullMedia = Foo()
    diff = Foo()
    diffMedia = Foo()

    fullIdmatched = False
    fullMediaIdmatched = False
    diffIdmatched = False
    diffMediaIdmatched = False

    for line in sqlprcStdoutLines:
        # full
        m1 = re.match("full\s+backupset\s+id\s*:\s*(\d+)", line)
        if m1:
            full.id = m1.groups()[0]
            fullIdmatched = True
        m1 = re.match("full\s+backupset\s+started\s*:\s*(.+)", line)
        if m1:
            full.started = m1.groups()[0]
        m1 = re.match("full\s+backupset\s+finished\s*:\s*(.+)", line)
        if m1:
            full.finished = m1.groups()[0]
        m1 = re.match("full\s+backupset\s+db\s+lsn\s*:\s*(.+)", line)
        if m1:
            full.lsn = m1.groups()[0]
        m1 = re.match("full\s+backupset\s+media\s+id\s*:\s*(.+)", line)
        if m1:
            fullMedia.id = m1.groups()[0]
            fullMediaIdmatched = True
        m1 = re.match("full\s+media\s+file\s*:\s*(.+)", line)
        if m1:
            if m1.groups()[0] in fix_backup_path_replace:
                fullMedia.file = fix_backup_path_replace[m1.groups()[0]]
            else:
                fullMedia.file = m1.groups()[0]
        m1 = re.match("full\s+media\s+position\s*:\s*(.+)", line)
        if m1:
            fullMedia.position = m1.groups()[0]

            # diff
        m1 = re.match("diff\s+backupset\s+id\s*:\s*(\d+)", line)
        if m1:
            diff.id = m1.groups()[0]
            diffIdmatched = True
        m1 = re.match("diff\s+backupset\s+started\s*:\s*(.+)", line)
        if m1:
            diff.started = m1.groups()[0]
        m1 = re.match("diff\s+backupset\s+finished\s*:\s*(.+)", line)
        if m1:
            diff.finished = m1.groups()[0]
        m1 = re.match("diff\s+backupset\s+db\s+lsn\s*:\s*(.+)", line)
        if m1:
            diff.lsn = m1.groups()[0]
        m1 = re.match("diff\s+backupset\s+media\s+id\s*:\s*(.+)", line)
        if m1:
            diffMedia.id = m1.groups()[0]
            diffMediaIdmatched = True
        m1 = re.match("diff\s+media\s+file\s*:\s*(.+)", line)
        if m1:
            if m1.groups()[0] in fix_backup_path_replace:
                diffMedia.file = fix_backup_path_replace[m1.groups()[0]]
            else:
                diffMedia.file = m1.groups()[0]
        m1 = re.match("diff\s+media\s+position\s*:\s*(.+)", line)
        if m1:
            diffMedia.position = m1.groups()[0]

    if not fullIdmatched:
        return None

    if fullMediaIdmatched:
        full.media = fullMedia

    res.full = full

    if diffIdmatched:
        res.diff = diff
        if diffMediaIdmatched:
            res.diff.media = diffMedia

    return res
Пример #21
0
 def setUp(self):
     Foo.clear()
Пример #22
0
def main():
  foo = Foo(100)
  foo.show()
Пример #23
0
from foo import Foo

print(Foo().scope)
Пример #24
0
from foo import Foo
from bar import Bar

if __name__ == '__main__':
    b = Bar()
    print b.get_font()
    f = Foo()
    print f.get_font()
    
    b.set_font('bar')
    print b.get_font()
    print f.get_font()
    pass
Пример #25
0
 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)
Пример #26
0
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()),
Пример #27
0
def index():
    foos = Foo.get_two_foos()
    return render_template('index.html', foos=foos, list_foos=Foo.get_liste())
Пример #28
0
 def test_on_peut_avoir_plein_de_foo(self):
     liste_foo = Foo.get_liste()
     for foo in liste_foo:
         self.assertIsInstance(foo.name, str)
         self.assertIsInstance(foo.score, float)
         self.assertIsInstance(foo.__html__(), str)
Пример #29
0
 def setUp(self):
     Foo.clear()
Пример #30
0
def what_is_love():
	f = Foo()
	return f.what_is_love(my_global_var)
Пример #31
0
    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])
Пример #32
0
def require_file_module():
	f = Foo()
	return f.bar()
Пример #33
0
 def test_clear(self):
     foo = Foo('ciclout')
     Foo.ajouter(foo)
     Foo.clear()
     self.assertEqual(Foo.get_liste(), [])
Пример #34
0
 def test_on_peut_ajouter_des_foos(self):
     foo = Foo('ciblout')
     Foo.ajouter(foo)
     self.assertIn(foo, foo.get_liste())
Пример #35
0
 def __init__(self):
     self.__foo = Foo(42, 'Fish', [0, 1, 2, 3])
Пример #36
0
 def test_on_peut_renvoyer_du_hteumeuleu(self):
     foo = Foo('superFooMash')
     self.assertIsInstance(foo.__html__(), str)
Пример #37
0
 def test_on_peut_renvoyer_du_hteumeuleu(self):
     foo = Foo('superFooMash')
     self.assertIsInstance(foo.__html__(), str)
Пример #38
0
 def test_on_peut_avoir_plein_de_foo(self):
     liste_foo = Foo.get_liste()
     for foo in liste_foo:
         self.assertIsInstance(foo.name, str)
         self.assertIsInstance(foo.score, float)
         self.assertIsInstance(foo.__html__(), str)
Пример #39
0
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()
Пример #40
0
def vote():
    foo = Foo.get_by_name(request.args['name'])
    other = Foo.get_by_name(request.args['other'])
    foo.a_vaincu(other)
    return redirect("/")
Пример #41
0
 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)
Пример #42
0
 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)
Пример #43
0
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()
Пример #44
0
 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)
Пример #45
0
def vote():
    foo = Foo.get_by_name(request.args['name'])
    other = Foo.get_by_name(request.args['other'])
    foo.a_vaincu(other)
    return redirect("/")
Пример #46
0
#!/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()
Пример #47
0
def index():
    foos = Foo.get_two_foos()
    return render_template('index.html', foos=foos, list_foos=Foo.get_liste())
Пример #48
0
 def test_bar(self):
     foo_instance = Foo()
     self.assertEquals(foo_instance.bar(x=32), 64)
Пример #49
0
def main():
    foo = [Foo(luca.status()), Foo(dishroom()), Foo(huh()), Foo(sports())]
    for f in foo:
        print(f.say())