Beispiel #1
0
    def test_set_has_many(self):
        # First, make a few pics
        pics = [self.picture]
        for _ in range(3):
            pic = yield Picture(name="a pic").save()
            pics.append(pic)
        picids = [int(p.id) for p in pics]

        yield self.user.pictures.set(pics)
        results = yield self.user.pictures.get()
        resultids = [int(p.id) for p in results]
        picids.sort()
        resultids.sort()
        self.assertEqual(picids, resultids)

        # now try resetting
        pics = []
        for _ in range(3):
            pic = yield Picture(name="a pic").save()
            pics.append(pic)
        picids = [p.id for p in pics]

        yield self.user.pictures.set(pics)
        results = yield self.user.pictures.get()
        resultids = [p.id for p in results]
        self.assertEqual(picids, resultids)
Beispiel #2
0
class CMC7:
    def __init__(self, scanJPGA4file):
        self.scan = Picture(scanJPGA4file)
        self.scan.crop(coordcheque)
        self.CMC7_01 = Matrix01(self.scan.matrix)  # 0.04
        self.digits = self.CMC7_01.extractDigits()  # 0.12

    # returns a Vector containing all the pixel of the ith digit
    def digitToVector(self, i):
        return matToVector(self.digits[i].m)

    # opens the scan, waits for a correct input which needs to be the CMC7 code
    def toTrainingString(self):
        self.scan.im.show()
        res = ""
        code = input().replace(" ", "")
        while len(code) != nbDigits:
            print("incorrect")
            code = input().replace(" ", "")
        for proc in psutil.process_iter():
            if proc.name() == "dllhost.exe":
                proc.kill()
        for i in range(nbDigits):
            res += vecToString(matToVector(
                self.digits[i].m)) + digcode[code[i]] + "\n"
        return res
Beispiel #3
0
class CMC7:
    def __init__(self, scanJPGA4file):
        self.scan = Picture(scanJPGA4file)
        self.scan.crop(coordcheque)
        self.CMC7_01 = Matrix01(self.scan.matrix) # 0.04
        self.digits = self.CMC7_01.extractDigits() # 0.12

    # returns a Vector containing all the pixel of the ith digit
    def digitToVector(self, i):
        return matToVector(self.digits[i].m)

    # opens the scan, waits for a correct input which needs to be the CMC7 code
    def toTrainingString(self):
        self.scan.im.show()
        res = ""
        code = input().replace(" ", "")
        while len(code)!= nbDigits:
            print("incorrect")
            code = input().replace(" ", "")
        for proc in psutil.process_iter():
            if proc.name() == "dllhost.exe":
                proc.kill()
        for i in range(nbDigits):
            res += vecToString(matToVector(self.digits[i].m)) +digcode[code[i]] + "\n"
        return res
Beispiel #4
0
 def test_clear_belongs_to(self):
     picture = yield Picture(name="a pic", size=10,
                             user_id=self.user.id).save()
     yield picture.user.clear()
     user = yield picture.user.get()
     self.assertEqual(user, None)
     yield picture.refresh()
     user = yield picture.user.get()
     self.assertEqual(user, None)
Beispiel #5
0
    def test_has_many_count_with_args(self):
        # First, make a few pics
        ids = [self.picture.id]
        for _ in range(3):
            pic = yield Picture(user_id=self.user.id).save()
            ids.append(pic.id)

        picsnum = yield self.user.pictures.count(where=['name = ?', 'a pic'])
        self.assertEqual(picsnum, 1)
Beispiel #6
0
    def test_has_many_count(self):
        # First, make a few pics
        ids = [self.picture.id]
        for _ in range(3):
            pic = yield Picture(user_id=self.user.id).save()
            ids.append(pic.id)

        totalnum = yield self.user.pictures.count()
        self.assertEqual(totalnum, 4)
Beispiel #7
0
 def setUp(self):
     yield initDB(self)
     self.user = yield User(first_name="First", last_name="Last",
                            age=10).save()
     self.avatar = yield Avatar(name="an avatar name",
                                user_id=self.user.id).save()
     self.picture = yield Picture(name="a pic",
                                  size=10,
                                  user_id=self.user.id).save()
     self.dbconfig = Registry.getConfig()
Beispiel #8
0
    def test_has_many(self):
        # First, make a few pics
        ids = [self.picture.id]
        for _ in range(3):
            pic = yield Picture(user_id=self.user.id).save()
            ids.append(pic.id)

        pics = yield self.user.pictures.get()
        picids = [p.id for p in pics]
        self.assertEqual(ids, picids)
Beispiel #9
0
 def setUp(self):
     yield initDB(self)
     self.user = yield User(first_name="First", last_name="Last",
                            age=10).save()
     self.avatar = yield Avatar(name="an avatar name",
                                user_id=self.user.id).save()
     self.picture = yield Picture(name="a pic",
                                  size=10,
                                  user_id=self.user.id).save()
     self.favcolor = yield FavoriteColor(name="blue").save()
     self.boy = yield Boy(name="Robert").save()
     self.girl = yield Girl(name="Susan").save()
     self.config = Registry.getConfig()
Beispiel #10
0
    def test_clear_has_many(self):
        pics = [self.picture]
        for _ in range(3):
            pic = yield Picture(name="a pic").save()
            pics.append(pic)

        yield self.user.pictures.set(pics)
        yield self.user.pictures.clear()

        userpics = yield self.user.pictures.get()
        self.assertEqual(userpics, [])

        # even go so far as to refetch user
        yield User.find(self.user.id)
        userpics = yield self.user.pictures.get()
        self.assertEqual(userpics, [])

        # picture records should be updated
        pics = yield Picture.find(where=["user_id=?", self.user.id])
        self.assertEqual(pics, [])

        # but still exist
        pics = yield Picture.all()
        self.assertEqual(len(pics), 4)
Beispiel #11
0
    def test_clear_has_many(self):
        pics = [self.picture]
        for _ in range(3):
            pic = yield Picture(name="a pic").save()
            pics.append(pic)

        yield self.user.pictures.set(pics)
        yield self.user.pictures.clear()

        userpics = yield self.user.pictures.get()
        self.assertEqual(userpics, [])

        # even go so far as to refetch user
        yield User.find(self.user.id)
        userpics = yield self.user.pictures.get()
        self.assertEqual(userpics, [])

        # picture records should be updated
        pics = yield Picture.find(where=["user_id=?", self.user.id])
        self.assertEqual(pics, [])

        # but still exist
        pics = yield Picture.all()
        self.assertEqual(len(pics), 4)
Beispiel #12
0
 def test_set_on_unsaved(self):
     yield User(first_name="new one").save()
     picture = Picture(name="a pic")
     self.assertRaises(ReferenceNotSavedError, getattr, picture, 'user')
Beispiel #13
0
 def __init__(self, scanJPGA4file):
     self.scan = Picture(scanJPGA4file)
     self.scan.crop(coordcheque)
     self.CMC7_01 = Matrix01(self.scan.matrix)  # 0.04
     self.digits = self.CMC7_01.extractDigits()  # 0.12
Beispiel #14
0
 def __init__(self, scanJPGA4file):
     self.scan = Picture(scanJPGA4file)
     self.scan.crop(coordcheque)
     self.CMC7_01 = Matrix01(self.scan.matrix) # 0.04
     self.digits = self.CMC7_01.extractDigits() # 0.12