Skip to content

Commit 37cad8a

Browse files
Kiuk Chungfacebook-github-bot
authored andcommitted
fix broken tests (#7)
Summary: Pull Request resolved: #7 `get_file_contents` method in `cmd_run` was not properly implemented (was trying to read from `$root/torchx/cli/torchx/cli/conf` intead of `$root/torchx/cli/conf`) Reviewed By: drdarshan Differential Revision: D28620895 fbshipit-source-id: 8eabd9feb8915dbba6077f783ecb5ecc6ffd109b
1 parent d02e572 commit 37cad8a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

torchx/cli/cmd_run.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ def get_file_contents(conf_file: str) -> Optional[str]:
107107
Example: ``get_file("torchx/cli/config/foo.txt")``
108108
"""
109109

110-
root = path.dirname(__file__).replace(__name__.replace(".", path.sep), "")
110+
module = __name__.replace(".", path.sep) # torchx/cli/cmd_run
111+
module_path, _ = path.splitext(__file__) # $root/torchx/cli/cmd_run
112+
root = module_path.replace(module, "")
111113
abspath = path.join(root, conf_file)
114+
112115
if path.exists(abspath):
113116
with open(abspath, "r") as f:
114117
return f.read()

torchx/cli/test/cmd_run_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from typing import Generator
1616
from unittest.mock import MagicMock, patch
1717

18-
from torchx.cli.cmd_run import CmdBuiltins, CmdRun, _builtins
18+
from torchx.cli.cmd_run import CmdBuiltins, CmdRun, _builtins, get_file_contents
1919

2020

2121
@contextmanager
@@ -120,6 +120,10 @@ def test_run_dryrun(self, mock_runner_run: MagicMock) -> None:
120120
self.cmd_run.run(args)
121121
mock_runner_run.assert_not_called()
122122

123+
def test_get_file_contents(self) -> None:
124+
content = get_file_contents("torchx/cli/config/echo.torchx")
125+
self.assertIsNotNone(content)
126+
123127

124128
class CmdBuiltinTest(unittest.TestCase):
125129
def test_run(self) -> None:

0 commit comments

Comments
 (0)