Skip to content

Commit 2b0556e

Browse files
Rong Rong (AI Infra)facebook-github-bot
authored andcommitted
Enable GPU/RE teags for pytorch/*/TARGETS that needs GPU (#3370)
Summary: Pull Request resolved: #3370 Pull Request resolved: #3361 Convert pytorch_gpu to use GPU/RE Reviewed By: datumbox Differential Revision: D26264102 fbshipit-source-id: b45179215ecb1142f6468386c4fee1759dd82f0c
1 parent 0fb54ba commit 2b0556e

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

test/_utils_internal.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
3+
4+
# Get relative file path
5+
# this returns relative path from current file.
6+
def get_relative_path(curr_file, *path_components):
7+
return os.path.join(os.path.dirname(curr_file), *path_components)

test/common_utils.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from numbers import Number
1515
from torch._six import string_classes
1616
from collections import OrderedDict
17+
from _utils_internal import get_relative_path
1718

1819
import numpy as np
1920
from PIL import Image
@@ -106,19 +107,23 @@ def remove_prefix_suffix(text, prefix, suffix):
106107
# lives, NOT where test/common_utils.py lives.
107108
module_id = self.__class__.__module__
108109
munged_id = remove_prefix_suffix(self.id(), module_id + ".", strip_suffix)
109-
test_file = os.path.realpath(sys.modules[module_id].__file__)
110-
expected_file = os.path.join(os.path.dirname(test_file),
111-
"expect",
112-
munged_id)
113110

111+
# Determine expected file based on environment
112+
expected_file_base = get_relative_path(
113+
os.path.realpath(sys.modules[module_id].__file__),
114+
"expect")
115+
116+
# Set expected_file based on subname.
117+
expected_file = os.path.join(expected_file_base, munged_id)
114118
if subname:
115119
expected_file += "_" + subname
116120
expected_file += "_expect.pkl"
117121

118122
if not ACCEPT and not os.path.exists(expected_file):
119123
raise RuntimeError(
120-
("No expect file exists for {}; to accept the current output, run:\n"
121-
"python {} {} --accept").format(os.path.basename(expected_file), __main__.__file__, munged_id))
124+
f"No expect file exists for {os.path.basename(expected_file)} in {expected_file}; "
125+
"to accept the current output, run:\n"
126+
f"python {__main__.__file__} {munged_id} --accept")
122127

123128
return expected_file
124129

0 commit comments

Comments
 (0)