コード例 #1
0
ファイル: fix_faker.py プロジェクト: zhutony/psycopg3
    def get_supported_types(self):
        dumpers = self.conn.adapters._dumpers[Format.as_pq(self.format)]
        rv = set()
        for cls in dumpers.keys():
            if isinstance(cls, str):
                cls = deep_import(cls)
            rv.add(cls)

        # check all the types are handled
        for cls in rv:
            self.get_maker(cls)

        return rv
コード例 #2
0
def test_random(conn, faker, fmt):
    faker.format = fmt
    faker.choose_schema(ncols=20)
    faker.make_records(50)

    with conn.cursor(binary=Format.as_pq(fmt)) as cur:
        cur.execute(faker.drop_stmt)
        cur.execute(faker.create_stmt)
        cur.executemany(faker.insert_stmt, faker.records)
        cur.execute(faker.select_stmt)
        recs = cur.fetchall()

    for got, want in zip(recs, faker.records):
        faker.assert_record(got, want)
コード例 #3
0
def test_leak(dsn, faker, fmt, fetch, row_factory):
    faker.format = fmt
    faker.choose_schema(ncols=5)
    faker.make_records(10)
    row_factory = getattr(rows, row_factory)

    n = []
    for i in range(3):
        with psycopg3.connect(dsn) as conn:
            with conn.cursor(binary=Format.as_pq(fmt),
                             row_factory=row_factory) as cur:
                cur.execute(faker.drop_stmt)
                cur.execute(faker.create_stmt)
                cur.executemany(faker.insert_stmt, faker.records)
                cur.execute(faker.select_stmt)

                if fetch == "one":
                    while 1:
                        tmp = cur.fetchone()
                        if tmp is None:
                            break
                elif fetch == "many":
                    while 1:
                        tmp = cur.fetchmany(3)
                        if not tmp:
                            break
                elif fetch == "all":
                    cur.fetchall()
                elif fetch == "iter":
                    for rec in cur:
                        pass

                tmp = None

        del cur, conn
        gc.collect()
        gc.collect()
        n.append(len(gc.get_objects()))

    assert (n[0] == n[1] ==
            n[2]), f"objects leaked: {n[1] - n[0]}, {n[2] - n[1]}"