aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2024-06-17 04:24:14 +0800
committer简律纯 <i@jyunko.cn>2024-06-17 04:24:14 +0800
commitdfec9f99d1726b3c3a4e9426f50c955fcaddb623 (patch)
tree6037a833b14cabd5ffda9b5a09f08229994fa616 /tests
parente914584e3e441a5b875e68d9443d99a745164e34 (diff)
downloadHydroRoll-dfec9f99d1726b3c3a4e9426f50c955fcaddb623.tar.gz
HydroRoll-dfec9f99d1726b3c3a4e9426f50c955fcaddb623.zip
chore(format): ruff lint code
Diffstat (limited to 'tests')
-rw-r--r--tests/test_sqlite3.py56
1 files changed, 35 insertions, 21 deletions
diff --git a/tests/test_sqlite3.py b/tests/test_sqlite3.py
index 92b0f59..9a7080c 100644
--- a/tests/test_sqlite3.py
+++ b/tests/test_sqlite3.py
@@ -1,13 +1,14 @@
import sqlite3
+
class BottlePlugin:
def __init__(self):
- self.conn = sqlite3.connect('bottles.db')
+ self.conn = sqlite3.connect("bottles.db")
self.cursor = self.conn.cursor()
self.create_table()
def create_table(self):
- self.cursor.execute('''
+ self.cursor.execute("""
CREATE TABLE IF NOT EXISTS bottles (
id INTEGER PRIMARY KEY AUTOINCREMENT,
message TEXT NOT NULL,
@@ -15,48 +16,63 @@ class BottlePlugin:
receiver TEXT NOT NULL,
status INTEGER DEFAULT 0
);
- ''')
- self.cursor.execute('''
+ """)
+ self.cursor.execute("""
CREATE TABLE IF NOT EXISTS comments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
bottle_id INTEGER NOT NULL,
comment TEXT NOT NULL
);
- ''')
- self.cursor.execute('''
+ """)
+ self.cursor.execute("""
CREATE TABLE IF NOT EXISTS likes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
bottle_id INTEGER NOT NULL,
user TEXT NOT NULL
);
- ''')
+ """)
self.conn.commit()
def throw_bottle(self, message, sender):
- self.cursor.execute("INSERT INTO bottles (message, sender, receiver) VALUES (?, ?, '')", (message, sender))
+ self.cursor.execute(
+ "INSERT INTO bottles (message, sender, receiver) VALUES (?, ?, '')",
+ (message, sender),
+ )
self.conn.commit()
def pick_bottle(self, receiver):
- self.cursor.execute("SELECT id, message, sender FROM bottles WHERE receiver='' OR receiver=? ORDER BY RANDOM() LIMIT 1", (receiver,))
+ self.cursor.execute(
+ "SELECT id, message, sender FROM bottles WHERE receiver='' OR receiver=? ORDER BY RANDOM() LIMIT 1",
+ (receiver,),
+ )
row = self.cursor.fetchone()
if row is None:
return None
bottle_id, message, sender = row
- self.cursor.execute("UPDATE bottles SET receiver=? WHERE id=?", (receiver, bottle_id))
+ self.cursor.execute(
+ "UPDATE bottles SET receiver=? WHERE id=?", (receiver, bottle_id)
+ )
self.conn.commit()
- return {'id': bottle_id, 'message': message, 'sender': sender}
+ return {"id": bottle_id, "message": message, "sender": sender}
def add_comment(self, bottle_id, comment):
- self.cursor.execute("INSERT INTO comments (bottle_id, comment) VALUES (?, ?)", (bottle_id, comment))
+ self.cursor.execute(
+ "INSERT INTO comments (bottle_id, comment) VALUES (?, ?)",
+ (bottle_id, comment),
+ )
self.conn.commit()
def get_comments(self, bottle_id):
- self.cursor.execute("SELECT comment FROM comments WHERE bottle_id=?", (bottle_id,))
+ self.cursor.execute(
+ "SELECT comment FROM comments WHERE bottle_id=?", (bottle_id,)
+ )
rows = self.cursor.fetchall()
return [row[0] for row in rows]
def like_bottle(self, bottle_id, user):
- self.cursor.execute("INSERT INTO likes (bottle_id, user) VALUES (?, ?)", (bottle_id, user))
+ self.cursor.execute(
+ "INSERT INTO likes (bottle_id, user) VALUES (?, ?)", (bottle_id, user)
+ )
self.conn.commit()
def get_likes(self, bottle_id):
@@ -71,27 +87,25 @@ class BottlePlugin:
self.conn.commit()
-
-
plugin = BottlePlugin()
# 扔一个漂流瓶
-plugin.throw_bottle('Hello, world!', 'Alice')
+plugin.throw_bottle("Hello, world!", "Alice")
# 捡一个漂流瓶
-bottle = plugin.pick_bottle('Bob')
+bottle = plugin.pick_bottle("Bob")
if bottle is not None:
print(bottle)
# 添加评论
-plugin.add_comment(1, 'Nice message!')
+plugin.add_comment(1, "Nice message!")
comments = plugin.get_comments(1)
print(comments)
# 点赞
-plugin.like_bottle(1, 'Charlie')
+plugin.like_bottle(1, "Charlie")
likes = plugin.get_likes(1)
print(likes)
# 清空漂流瓶
-# plugin.clear_bottles() \ No newline at end of file
+# plugin.clear_bottles()