|
14 | 14 | from numbers import Number
|
15 | 15 | from torch._six import string_classes
|
16 | 16 | from collections import OrderedDict
|
| 17 | +from _utils_internal import get_relative_path |
17 | 18 |
|
18 | 19 | import numpy as np
|
19 | 20 | from PIL import Image
|
@@ -106,19 +107,23 @@ def remove_prefix_suffix(text, prefix, suffix):
|
106 | 107 | # lives, NOT where test/common_utils.py lives.
|
107 | 108 | module_id = self.__class__.__module__
|
108 | 109 | 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) |
113 | 110 |
|
| 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) |
114 | 118 | if subname:
|
115 | 119 | expected_file += "_" + subname
|
116 | 120 | expected_file += "_expect.pkl"
|
117 | 121 |
|
118 | 122 | if not ACCEPT and not os.path.exists(expected_file):
|
119 | 123 | 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") |
122 | 127 |
|
123 | 128 | return expected_file
|
124 | 129 |
|
|
0 commit comments