auto: 일일 백업 2026-09-23 02:00

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hyowons
2026-09-23 02:00:05 +09:00
parent 408a3e0d4a
commit 0157b24a55
122 changed files with 1751 additions and 1238 deletions
@@ -0,0 +1,76 @@
import json
import sys
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch
SCRIPTS = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(SCRIPTS))
import stock_portfolio_report as report
class NxtInactiveCorrectionTests(unittest.TestCase):
def test_corrects_only_nxt_inactive_rows_with_krx_quote(self):
rows = [
{
'code': '381620', 'qty': 10, 'price': 6290, 'pred_close': 6290,
'day_change': 0, 'day_change_pct': 0.0, 'buy_amount': 58000,
'eval_value': 62900, 'profit': 4900, 'profit_rate': 8.45,
},
{
'code': '005930', 'qty': 2, 'price': 281000, 'pred_close': 275000,
'day_change': 6000, 'day_change_pct': 2.18, 'buy_amount': 500000,
'eval_value': 562000, 'profit': 62000, 'profit_rate': 12.4,
},
]
cache = {
'stocks': {
'제닉스로보틱스': {'code': '381620', 'nxt_enable': False},
'삼성전자': {'code': '005930', 'nxt_enable': True},
}
}
with tempfile.TemporaryDirectory() as td:
cache_path = Path(td) / 'stock_codes.json'
cache_path.write_text(json.dumps(cache))
with patch.object(report, 'STOCK_CODES_FILE', cache_path), patch.object(
report,
'get_watchlist_quotes',
return_value={
'381620': {'price': 6190, 'change': 40, 'change_pct': 0.65},
},
) as quotes:
corrected = report.correct_nxt_inactive_rows(rows)
self.assertEqual(corrected, 1)
quotes.assert_called_once_with(['381620'], exchange='KRX')
self.assertEqual(rows[0]['price'], 6190)
self.assertEqual(rows[0]['pred_close'], 6150)
self.assertEqual(rows[0]['eval_value'], 61900)
self.assertEqual(rows[0]['profit'], 3900)
self.assertAlmostEqual(rows[0]['profit_rate'], 3900 / 58000 * 100)
self.assertEqual(rows[1]['price'], 281000)
def test_keeps_original_row_when_krx_quote_is_missing(self):
row = {
'code': '381620', 'qty': 10, 'price': 6290, 'pred_close': 6290,
'day_change': 0, 'day_change_pct': 0.0, 'buy_amount': 58000,
'eval_value': 62900, 'profit': 4900, 'profit_rate': 8.45,
}
cache = {'stocks': {'제닉스로보틱스': {'code': '381620', 'nxt_enable': False}}}
with tempfile.TemporaryDirectory() as td:
cache_path = Path(td) / 'stock_codes.json'
cache_path.write_text(json.dumps(cache))
with patch.object(report, 'STOCK_CODES_FILE', cache_path), patch.object(
report, 'get_watchlist_quotes', return_value={}
):
corrected = report.correct_nxt_inactive_rows([row])
self.assertEqual(corrected, 0)
self.assertEqual(row['price'], 6290)
self.assertEqual(row['eval_value'], 62900)
if __name__ == '__main__':
unittest.main()