File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed
piccolo/apps/migrations/commands
tests/apps/migrations/commands Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -75,7 +75,8 @@ async def _create_new_migration(app_config: AppConfig, auto=False) -> None:
7575 )
7676
7777 if sum ([len (i .statements ) for i in alter_statements ]) == 0 :
78- sys .exit ("No changes detected - exiting." )
78+ print ("No changes detected - exiting." )
79+ sys .exit (0 )
7980
8081 file_contents = render_template (
8182 migration_id = _id ,
Original file line number Diff line number Diff line change 11import os
22import shutil
33from unittest import TestCase
4+ from unittest .mock import call , patch , MagicMock
45
5- from piccolo .conf .apps import AppConfig
66from piccolo .apps .migrations .commands .new import (
77 _create_new_migration ,
88 BaseMigrationManager ,
99 new ,
1010)
11+ from piccolo .conf .apps import AppConfig
1112from piccolo .utils .sync import run_sync
1213
1314from tests .base import postgres_only
@@ -41,13 +42,16 @@ def test_create_new_migration(self):
4142 self .assertTrue (len (migration_modules .keys ()) == 1 )
4243
4344 @postgres_only
44- def test_new_command (self ):
45+ @patch ("piccolo.apps.migrations.commands.new.print" )
46+ def test_new_command (self , print_ : MagicMock ):
4547 """
4648 Call the command, when no migration changes are needed.
4749 """
4850 with self .assertRaises (SystemExit ) as manager :
4951 run_sync (new (app_name = "example_app" , auto = True ))
5052
51- self .assertEqual (
52- manager .exception .__str__ (), "No changes detected - exiting."
53+ self .assertEqual (manager .exception .code , 0 )
54+
55+ self .assertTrue (
56+ print_ .mock_calls [- 1 ] == call ("No changes detected - exiting." )
5357 )
You can’t perform that action at this time.
0 commit comments