mirror of
https://github.com/farcasclaudiu/xtb-investment-tools.git
synced 2026-06-22 07:01:58 +03:00
Add warning suppression for openpyxl default style in portfolio scripts and tests
This commit is contained in:
+5
-2
@@ -22,14 +22,17 @@ _IMPL_PATH = (
|
||||
|
||||
|
||||
def _load_impl():
|
||||
module_name = __name__ if __name__ != "__main__" else "_xtb_wealthfolio_exporter_impl"
|
||||
script_dir = _IMPL_PATH.parent
|
||||
if str(script_dir) not in sys.path:
|
||||
sys.path.insert(0, str(script_dir))
|
||||
spec = importlib.util.spec_from_file_location(__name__, _IMPL_PATH)
|
||||
spec = importlib.util.spec_from_file_location(module_name, _IMPL_PATH)
|
||||
if spec is None or spec.loader is None:
|
||||
raise ImportError(f"Could not load XTB Wealthfolio implementation at {_IMPL_PATH}")
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[__name__] = module
|
||||
sys.modules[module_name] = module
|
||||
if __name__ != "__main__":
|
||||
sys.modules[__name__] = module
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import argparse
|
||||
import contextlib
|
||||
import io
|
||||
import re
|
||||
import warnings
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, date, timedelta
|
||||
from html import escape
|
||||
@@ -37,6 +38,18 @@ COST_FALLBACK_NOTES = {
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def suppress_openpyxl_default_style_warning() -> None:
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message=r"Workbook contains no default style, apply openpyxl's default",
|
||||
category=UserWarning,
|
||||
module=r"openpyxl\.styles\.stylesheet",
|
||||
)
|
||||
|
||||
|
||||
suppress_openpyxl_default_style_warning()
|
||||
|
||||
# XTB "Type" values that represent trading activity (not cash transfers).
|
||||
TRADE_TYPE_RE = re.compile(
|
||||
r"stock\s*(purchase|sale|buy|sell)|\bopen\b|\bclose\b",
|
||||
|
||||
@@ -2,6 +2,7 @@ import argparse
|
||||
import contextlib
|
||||
import io
|
||||
import re
|
||||
import warnings
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime, date, timedelta
|
||||
from html import escape
|
||||
@@ -37,6 +38,18 @@ COST_FALLBACK_NOTES = {
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def suppress_openpyxl_default_style_warning() -> None:
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message=r"Workbook contains no default style, apply openpyxl's default",
|
||||
category=UserWarning,
|
||||
module=r"openpyxl\.styles\.stylesheet",
|
||||
)
|
||||
|
||||
|
||||
suppress_openpyxl_default_style_warning()
|
||||
|
||||
# XTB "Type" values that represent trading activity (not cash transfers).
|
||||
TRADE_TYPE_RE = re.compile(
|
||||
r"stock\s*(purchase|sale|buy|sell)|\bopen\b|\bclose\b",
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import warnings
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
|
||||
@@ -44,6 +46,27 @@ def cash_row(type_, instrument, amount, comment="", time="2026-01-15 10:00:00"):
|
||||
# Generic helpers
|
||||
# ---------------------------------------------------------------------------
|
||||
class TestHelpers:
|
||||
def test_suppresses_openpyxl_default_style_warning_only(self):
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
warnings.simplefilter("default")
|
||||
main.suppress_openpyxl_default_style_warning()
|
||||
warnings.warn_explicit(
|
||||
"Workbook contains no default style, apply openpyxl's default",
|
||||
UserWarning,
|
||||
"stylesheet.py",
|
||||
237,
|
||||
module="openpyxl.styles.stylesheet",
|
||||
)
|
||||
warnings.warn_explicit(
|
||||
"Another workbook warning",
|
||||
UserWarning,
|
||||
"stylesheet.py",
|
||||
237,
|
||||
module="openpyxl.styles.stylesheet",
|
||||
)
|
||||
|
||||
assert [str(w.message) for w in caught] == ["Another workbook warning"]
|
||||
|
||||
def test_clean_columns_normalizes(self):
|
||||
df = pd.DataFrame(columns=["Open Price", "Profit/Loss", " Ticker "])
|
||||
out = clean_columns(df)
|
||||
|
||||
Reference in New Issue
Block a user