diff options
author | Caio Carvalho <21188280+lowercase00@users.noreply.github.com> | 2022-05-03 13:20:18 -0400 |
---|---|---|
committer | Federico Caselli <cfederico87@gmail.com> | 2022-05-06 20:30:39 +0000 |
commit | 0adcc749183abe17beab0baa07d8b1b1ac6a55d2 (patch) | |
tree | ea0bf6b93cf6021db77a5f6ccf5fce43dc5b389a /tests/test_script_production.py | |
parent | 1684d0ee89c0fc6b0b90bc5db614468b31119e9d (diff) | |
download | alembic-0adcc749183abe17beab0baa07d8b1b1ac6a55d2.tar.gz |
Add epoch as an option for file_template
Added new token ``epoch`` to the ``file_template`` option, which will
populate the integer epoch as determined by ``int(create_date.timestamp())``.
Pull request courtesy Caio Carvalho.
Fixes: #1027
Closes: #1028
Pull-request: https://github.com/sqlalchemy/alembic/pull/1028
Pull-request-sha: 27970cd5d4e047cb7aabd161c68b757b2ee3e4c4
Change-Id: I73e13009bae91e64681a605b3f0b62ea1e5fc464
Diffstat (limited to 'tests/test_script_production.py')
-rw-r--r-- | tests/test_script_production.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test_script_production.py b/tests/test_script_production.py index 05167f0..2cf9052 100644 --- a/tests/test_script_production.py +++ b/tests/test_script_production.py @@ -8,6 +8,7 @@ from sqlalchemy import inspect from alembic import autogenerate from alembic import command +from alembic import testing from alembic import util from alembic.environment import EnvironmentContext from alembic.operations import ops @@ -185,6 +186,33 @@ class ScriptNamingTest(TestBase): ), ) + @testing.combinations( + ( + datetime.datetime(2012, 7, 25, 15, 8, 5, tzinfo=tz.gettz("UTC")), + "%s/versions/1343228885_12345_this_is_a_" + "message_2012_7_25_15_8_5.py", + ), + ( + datetime.datetime(2012, 7, 25, 15, 8, 6, tzinfo=tz.gettz("UTC")), + "%s/versions/1343228886_12345_this_is_a_" + "message_2012_7_25_15_8_6.py", + ), + ) + def test_epoch(self, create_date, expected): + script = ScriptDirectory( + _get_staging_directory(), + file_template="%(epoch)s_%(rev)s_%(slug)s_" + "%(year)s_%(month)s_" + "%(day)s_%(hour)s_" + "%(minute)s_%(second)s", + ) + eq_( + script._rev_path( + script.versions, "12345", "this is a message", create_date + ), + os.path.abspath(expected % _get_staging_directory()), + ) + def _test_tz(self, timezone_arg, given, expected): script = ScriptDirectory( _get_staging_directory(), |