chore: Add deprecation warnings and update documentation (Task 9)
Task 9: Clean up legacy code - Added deprecation warnings to Serie.save_to_file() and load_from_file() - Updated infrastructure.md with Data Storage section documenting: - SQLite database as primary storage - Legacy file storage as deprecated - Data migration process - Added deprecation warning tests for Serie class - Updated existing tests to handle new warnings - All 1012 tests pass (872 unit + 55 API + 85 integration)
This commit is contained in:
@@ -173,6 +173,8 @@ class TestSerieProperties:
|
||||
|
||||
def test_serie_save_and_load_from_file(self):
|
||||
"""Test saving and loading Serie from file."""
|
||||
import warnings
|
||||
|
||||
serie = Serie(
|
||||
key="test-key",
|
||||
name="Test Series",
|
||||
@@ -190,11 +192,15 @@ class TestSerieProperties:
|
||||
temp_filename = f.name
|
||||
|
||||
try:
|
||||
# Save to file
|
||||
serie.save_to_file(temp_filename)
|
||||
|
||||
# Load from file
|
||||
loaded_serie = Serie.load_from_file(temp_filename)
|
||||
# Suppress deprecation warnings for this test
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", DeprecationWarning)
|
||||
|
||||
# Save to file
|
||||
serie.save_to_file(temp_filename)
|
||||
|
||||
# Load from file
|
||||
loaded_serie = Serie.load_from_file(temp_filename)
|
||||
|
||||
# Verify all properties match
|
||||
assert loaded_serie.key == serie.key
|
||||
@@ -242,3 +248,75 @@ class TestSerieDocumentation:
|
||||
assert Serie.folder.fget.__doc__ is not None
|
||||
assert "metadata" in Serie.folder.fget.__doc__.lower()
|
||||
assert "not used for lookups" in Serie.folder.fget.__doc__.lower()
|
||||
|
||||
|
||||
class TestSerieDeprecationWarnings:
|
||||
"""Test deprecation warnings for file-based methods."""
|
||||
|
||||
def test_save_to_file_raises_deprecation_warning(self):
|
||||
"""Test save_to_file() raises deprecation warning."""
|
||||
import warnings
|
||||
|
||||
serie = Serie(
|
||||
key="test-key",
|
||||
name="Test Series",
|
||||
site="https://example.com",
|
||||
folder="Test Folder",
|
||||
episodeDict={1: [1, 2, 3]}
|
||||
)
|
||||
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode='w', suffix='.json', delete=False
|
||||
) as temp_file:
|
||||
temp_filename = temp_file.name
|
||||
|
||||
try:
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
serie.save_to_file(temp_filename)
|
||||
|
||||
# Check deprecation warning was raised
|
||||
assert len(w) == 1
|
||||
assert issubclass(w[0].category, DeprecationWarning)
|
||||
assert "deprecated" in str(w[0].message).lower()
|
||||
assert "save_to_file" in str(w[0].message)
|
||||
finally:
|
||||
if os.path.exists(temp_filename):
|
||||
os.remove(temp_filename)
|
||||
|
||||
def test_load_from_file_raises_deprecation_warning(self):
|
||||
"""Test load_from_file() raises deprecation warning."""
|
||||
import warnings
|
||||
|
||||
serie = Serie(
|
||||
key="test-key",
|
||||
name="Test Series",
|
||||
site="https://example.com",
|
||||
folder="Test Folder",
|
||||
episodeDict={1: [1, 2, 3]}
|
||||
)
|
||||
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode='w', suffix='.json', delete=False
|
||||
) as temp_file:
|
||||
temp_filename = temp_file.name
|
||||
|
||||
try:
|
||||
# Save first (suppress warning for this)
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
serie.save_to_file(temp_filename)
|
||||
|
||||
# Now test loading
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
Serie.load_from_file(temp_filename)
|
||||
|
||||
# Check deprecation warning was raised
|
||||
assert len(w) == 1
|
||||
assert issubclass(w[0].category, DeprecationWarning)
|
||||
assert "deprecated" in str(w[0].message).lower()
|
||||
assert "load_from_file" in str(w[0].message)
|
||||
finally:
|
||||
if os.path.exists(temp_filename):
|
||||
os.remove(temp_filename)
|
||||
|
||||
@@ -473,10 +473,19 @@ class TestSerieListDeprecationWarnings:
|
||||
warnings.simplefilter("always")
|
||||
serie_list.add(sample_serie)
|
||||
|
||||
# Check deprecation warning was raised
|
||||
assert len(w) == 1
|
||||
assert issubclass(w[0].category, DeprecationWarning)
|
||||
assert "add_to_db()" in str(w[0].message)
|
||||
# Check at least one deprecation warning was raised for add()
|
||||
# (Note: save_to_file also raises a warning, so we may get 2)
|
||||
deprecation_warnings = [
|
||||
warning for warning in w
|
||||
if issubclass(warning.category, DeprecationWarning)
|
||||
]
|
||||
assert len(deprecation_warnings) >= 1
|
||||
# Check that one of them is from add()
|
||||
add_warnings = [
|
||||
warning for warning in deprecation_warnings
|
||||
if "add_to_db()" in str(warning.message)
|
||||
]
|
||||
assert len(add_warnings) == 1
|
||||
|
||||
def test_get_by_folder_raises_deprecation_warning(
|
||||
self, temp_directory, sample_serie
|
||||
|
||||
Reference in New Issue
Block a user