fix: 独立建库并整理离线依赖目录
This commit is contained in:
@@ -6,7 +6,9 @@ import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import types
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
import zipfile
|
||||
|
||||
from openpyxl import Workbook
|
||||
@@ -102,6 +104,25 @@ class PipelineTest(unittest.TestCase):
|
||||
self.assertEqual(connection.cursor_instance.inserted, [])
|
||||
self.assertTrue(connection.closed)
|
||||
|
||||
def test_mysql_store_creates_and_connects_to_own_database(self) -> None:
|
||||
bootstrap = BootstrapConnection()
|
||||
target = object()
|
||||
calls: list[dict[str, object]] = []
|
||||
|
||||
def connect(**kwargs: object) -> object:
|
||||
calls.append(kwargs)
|
||||
return bootstrap if len(calls) == 1 else target
|
||||
|
||||
with patch.dict("sys.modules", {"pymysql": types.SimpleNamespace(connect=connect)}):
|
||||
connection = main.MySQLSummaryStore()._connect()
|
||||
|
||||
self.assertIs(connection, target)
|
||||
self.assertNotIn("database", calls[0])
|
||||
self.assertEqual(calls[1]["database"], "interference_etl")
|
||||
self.assertIn("CREATE DATABASE IF NOT EXISTS `interference_etl`", bootstrap.cursor_instance.executed[0])
|
||||
self.assertTrue(bootstrap.cursor_instance.closed)
|
||||
self.assertTrue(bootstrap.closed)
|
||||
|
||||
|
||||
class RecordingStore:
|
||||
def __init__(self) -> None:
|
||||
@@ -167,6 +188,30 @@ class FakeConnection:
|
||||
self.closed = True
|
||||
|
||||
|
||||
class BootstrapCursor:
|
||||
def __init__(self) -> None:
|
||||
self.executed: list[str] = []
|
||||
self.closed = False
|
||||
|
||||
def execute(self, query: str) -> None:
|
||||
self.executed.append(" ".join(query.split()))
|
||||
|
||||
def close(self) -> None:
|
||||
self.closed = True
|
||||
|
||||
|
||||
class BootstrapConnection:
|
||||
def __init__(self) -> None:
|
||||
self.cursor_instance = BootstrapCursor()
|
||||
self.closed = False
|
||||
|
||||
def cursor(self) -> BootstrapCursor:
|
||||
return self.cursor_instance
|
||||
|
||||
def close(self) -> None:
|
||||
self.closed = True
|
||||
|
||||
|
||||
def database_row() -> dict[str, str]:
|
||||
return {
|
||||
"hour_start": "2026-07-31 10:00:00",
|
||||
|
||||
Reference in New Issue
Block a user