Skip to content

Commit bcc7f5f

Browse files
committed
WIP: fixing tests
1 parent 6b2a56b commit bcc7f5f

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

migrations/migration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def get_previous_migration_id(self, filename: str) -> str:
6363
for line in migration_file:
6464
match = re.match(r"# Previous version: (.+)", line)
6565
if match:
66-
prev_migration_id = match.group(1)
66+
prev_migration_id = match.group(1) if match != 'None' else None
6767
break
6868
return prev_migration_id
6969

tests/migration_test.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def test_build_migration_sequence_with_dependencies(mock_get_previous_migration_
3030
with patch.object(Migration, 'get_migration_files', return_value=mock_filenames):
3131
# Mock the output of get_previous_migration_id
3232
mock_get_previous_migration_id.side_effect = {
33-
'migration2.py': 'migration1',
34-
'migration3.py': 'migration2',
35-
'migration1.py': None
33+
'migration2': 'migration1',
34+
'migration3': 'migration2',
35+
'migration1': None
3636
}.get
3737

3838
# Instantiate YourClass
@@ -51,16 +51,17 @@ def test_build_migration_sequence_with_circular_dependency(mock_get_previous_mig
5151
with patch.object(Migration, 'get_migration_files', return_value=mock_filenames):
5252
# Mock the output of get_previous_migration_id to create circular dependency
5353
mock_get_previous_migration_id.side_effect = {
54-
'migration2.py': 'migration1',
55-
'migration1.py': 'migration2'
54+
'migration2': 'migration1',
55+
'migration1': 'migration2'
5656
}.get
5757

5858
# Instantiate YourClass
5959
your_instance = Migration()
6060

61-
# Call the method to test
62-
with pytest.raises(ValueError):
61+
# Call the method to test and assert the raised ValueError with the expected message
62+
with pytest.raises(ValueError) as exc_info:
6363
your_instance.build_migration_sequence()
64+
assert str(exc_info.value) == "Cycle detected in migration sequence for migration1.py"
6465

6566
def test_build_migration_sequence(migration_instance):
6667
migration_sequence = migration_instance.build_migration_sequence()

0 commit comments

Comments
 (0)