Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Fix the exception when use __file__ attribute in .py config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiaohei committed Nov 19, 2019
1 parent e5d48d6 commit fb62756
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion orator/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def _get_config(self, path=None):
config = {}

with open(path) as fh:
exec(fh.read(), {}, config)
exec(fh.read(), {"__file__": path}, config)
else:
raise RuntimeError("Config file [%s] is not supported." % path)

Expand Down
2 changes: 1 addition & 1 deletion tests/commands/migrations/test_make_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_basic_create_gives_creator_proper_arguments_when_table_is_set(self):
self.run_command(command, [("name", "create_foo"), ("--table", "users")])

def test_basic_create_gives_creator_proper_arguments_when_table_is_set_with_create(
self
self,
):
creator_mock = flexmock(MigrationCreator)
creator_mock.should_receive("create").once().with_args(
Expand Down
35 changes: 35 additions & 0 deletions tests/commands/test_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding:utf-8 -*-
import os
import tempfile

from flexmock import flexmock

from orator.commands.command import Command

from . import OratorCommandTestCase


class FooCommand(Command):
"""
Test Command
"""

name = "foo"

def handle(self):
pass


class CommandTestCase(OratorCommandTestCase):
def test_get_py_config_and_require___file__(self):
filename = tempfile.mktemp(".py")
with open(filename, "w") as f:
f.write("foo = __file__")

command = flexmock(FooCommand())
command.should_call("_get_config").and_return({"foo": filename})

self.run_command(command, [("-c", filename)])

if os.path.exists(filename):
os.remove(filename)
2 changes: 1 addition & 1 deletion tests/migrations/test_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_last_batch_of_migrations_can_be_rolled_back(self):
migrator.rollback(os.getcwd())

def test_last_batch_of_migrations_can_be_rolled_back_directly_if_transactional_is_false(
self
self,
):
resolver_mock = flexmock(DatabaseManager)
resolver_mock.should_receive("connection").and_return({})
Expand Down

0 comments on commit fb62756

Please sign in to comment.