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

Commit f4fd11e

Browse files
luoxiaoheiluoxiaohei
authored and
luoxiaohei
committed
Fix the exception when use __file__ attribute in .py config file.
1 parent e5d48d6 commit f4fd11e

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

orator/commands/command.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _get_config(self, path=None):
123123
config = {}
124124

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

tests/commands/migrations/test_make_command.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def test_basic_create_gives_creator_proper_arguments_when_table_is_set(self):
3131
self.run_command(command, [("name", "create_foo"), ("--table", "users")])
3232

3333
def test_basic_create_gives_creator_proper_arguments_when_table_is_set_with_create(
34-
self
34+
self,
3535
):
3636
creator_mock = flexmock(MigrationCreator)
3737
creator_mock.should_receive("create").once().with_args(

tests/commands/test_command.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding:utf-8 -*-
2+
import os
3+
import tempfile
4+
5+
from flexmock import flexmock
6+
7+
from orator.commands.command import Command
8+
9+
from . import OratorCommandTestCase
10+
11+
12+
class FooCommand(Command):
13+
"""
14+
Test Command
15+
"""
16+
17+
name = "foo"
18+
19+
def handle(self):
20+
pass
21+
22+
23+
class CommandTestCase(OratorCommandTestCase):
24+
def test_get_py_config_and_require___file__(self):
25+
filename = tempfile.mktemp(".py")
26+
with open(filename, "w") as f:
27+
f.write("foo = __file__")
28+
29+
command = flexmock(FooCommand())
30+
command.should_call("_get_config").and_return({"foo": filename})
31+
32+
self.run_command(command, [("-c", filename)])
33+
34+
if os.path.exists(filename):
35+
os.remove(filename)

tests/migrations/test_migrator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def test_last_batch_of_migrations_can_be_rolled_back(self):
224224
migrator.rollback(os.getcwd())
225225

226226
def test_last_batch_of_migrations_can_be_rolled_back_directly_if_transactional_is_false(
227-
self
227+
self,
228228
):
229229
resolver_mock = flexmock(DatabaseManager)
230230
resolver_mock.should_receive("connection").and_return({})

0 commit comments

Comments
 (0)