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

add __file__ attribute when load .py config file #333

Open
wants to merge 1 commit into
base: 0.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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