From ab7b8f342a89c752460d171cd50d1f958c7d59c9 Mon Sep 17 00:00:00 2001 From: Aviskar KC Date: Thu, 4 Jul 2019 21:14:50 +0545 Subject: [PATCH] Add additional test cases --- tests/test_command.py | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tests/test_command.py b/tests/test_command.py index 933d7c8d..51533125 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -2,6 +2,7 @@ from contextlib import contextmanager import inspect from io import BytesIO from io import TextIOWrapper +import os import re from sqlalchemy import exc as sqla_exc @@ -811,3 +812,80 @@ class CommandLineTest(TestBase): self.cfg, directory=directory, ) + + def test_init_file_exists_and_is_empty(self): + def access_(path, mode): + if "generic" in path or path == "foobar": + return True + else: + return False + + def listdir_(path): + if path == "foobar": + return [] + else: + return ["file1", "file2", "alembic.ini.mako"] + + template_dir = self.cfg.get_template_directory() + + with mock.patch( + "alembic.command.os.access", side_effect=access_ + ) as access, mock.patch( + "alembic.command.os.makedirs" + ) as makedirs, mock.patch( + "alembic.command.os.listdir", side_effect=listdir_ + ) as listdir, mock.patch( + "alembic.command.ScriptDirectory" + ): + command.init(self.cfg, directory="foobar") + eq_( + access.mock_calls, + [ + mock.call("foobar", os.F_OK), + mock.call(os.path.join(template_dir, "generic"), os.F_OK), + mock.call("foobar", os.F_OK), + mock.call( + os.path.abspath("./scratch/test_alembic.ini"), os.F_OK + ), + ], + ) + eq_( + listdir.mock_calls, + [ + mock.call("foobar"), + mock.call(os.path.join(template_dir, "generic")), + ], + ) + eq_(makedirs.mock_calls, [mock.call("foobar/versions")]) + + def test_init_file_doesnt_exist(self): + def access_(path, mode): + if "generic" in path: + return True + else: + return False + + template_dir = self.cfg.get_template_directory() + with mock.patch( + "alembic.command.os.access", side_effect=access_ + ) as access, mock.patch( + "alembic.command.os.makedirs" + ) as makedirs, mock.patch( + "alembic.command.ScriptDirectory" + ): + command.init(self.cfg, directory="foobar") + eq_( + access.mock_calls, + [ + mock.call("foobar", os.F_OK), + mock.call(os.path.join(template_dir, "generic"), os.F_OK), + mock.call("foobar", os.F_OK), + mock.call( + os.path.abspath("./scratch/test_alembic.ini"), os.F_OK + ), + ], + ) + eq_( + makedirs.mock_calls, + [mock.call("foobar"), mock.call("foobar/versions")], + ) -- 2.47.2