mirror of
https://github.com/0xrsydn/idx-cli.git
synced 2026-08-07 01:33:52 +00:00
feat(rubick): rename project and add production release bundle
This commit is contained in:
commit
fab6cf26eb
33 changed files with 11554 additions and 0 deletions
49
tests/test_export_simple.py
Normal file
49
tests/test_export_simple.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import json
|
||||
import sqlite3
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from scripts.export_simple import export_csv, export_json, export_xlsx
|
||||
|
||||
|
||||
class ExportSimpleTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.base = Path(self.tmp.name)
|
||||
self.db = self.base / "test.db"
|
||||
conn = sqlite3.connect(self.db)
|
||||
conn.execute("CREATE TABLE stocks (id TEXT, ticker TEXT)")
|
||||
conn.execute("INSERT INTO stocks VALUES ('1','BBCA')")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def tearDown(self):
|
||||
self.tmp.cleanup()
|
||||
|
||||
def test_export_json(self):
|
||||
conn = sqlite3.connect(self.db)
|
||||
out = self.base / "json"
|
||||
export_json(conn, out, ["stocks"])
|
||||
conn.close()
|
||||
data = json.loads((out / "stocks.json").read_text())
|
||||
self.assertEqual(data[0]["ticker"], "BBCA")
|
||||
|
||||
def test_export_csv(self):
|
||||
conn = sqlite3.connect(self.db)
|
||||
out = self.base / "csv"
|
||||
export_csv(conn, out, ["stocks"])
|
||||
conn.close()
|
||||
text = (out / "stocks.csv").read_text()
|
||||
self.assertIn("BBCA", text)
|
||||
|
||||
def test_export_xlsx(self):
|
||||
conn = sqlite3.connect(self.db)
|
||||
out = self.base / "out.xlsx"
|
||||
export_xlsx(conn, out, ["stocks"])
|
||||
conn.close()
|
||||
self.assertTrue(out.exists())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue