pytorch/torch/csrc/jit/python
Yanan Cao c068233300 Add CHECK-SOURCE-HIGHLIGHTED to file check utils. (#39692)
Summary:
Enhance FileCheck util to check for highlighted source ranges. This is useful when writing tests regarding generated error messages that require source code highlighting.

Here is how the error looks like in different cases:

- In case of needed source code token not found at all in input string:
```
RuntimeError: Expected to find "invalid_token" but did not find it
Searched string:

...  <--- HERE
def to_list_missing_type_annotation(x):
    # type: (torch.Tensor) -> List[float]
From CHECK-SOURCE-HIGHLIGHTED: invalid_token
```

- In case of source code token not highlighted:
```
Traceback (most recent call last):
  File "test_range.py", line 11, in <module>
    FileCheck().check_source_highlighted("x.tolist()").run(s)
RuntimeError: Expected to find "~~~~~~~~~~" but did not find it
Searched string:
    # type: (torch.Tensor) -> List[float]
    li = x.tolist()
         ~~~~~~~~~ <--- HERE
         ~~~~~~~~~~~~~~~~~~~...  <--- HERE
    return li
```

It is a bit confusing since both input text (usually an error message) and generated error messages have their highlighted portions, but this is consistent of previous behavior. Another option is to generate plain error messages without additional range highlighting on input text.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/39692

Test Plan:
Added unit test.

Closes https://github.com/pytorch/pytorch/issues/38698

Differential Revision: D22001765

Pulled By: gmagogsfm

fbshipit-source-id: 6681441eee5853ab061d198ccfe55ebffddca202
2020-06-11 23:47:07 -07:00
..
init.cpp graph mode: add quantization type enum (#39795) 2020-06-10 21:34:23 -07:00
init.h
module_python.h [jit] kill script namespace (#34515) 2020-03-11 23:32:48 -07:00
pybind_utils.h [JIT] Add Type::repr_str to return human-readable str (#39544) 2020-06-10 12:01:24 -07:00
pybind.h [JIT] clang-format JIT code (#35115) 2020-03-26 11:24:51 -07:00
python_arg_flatten.cpp [JIT] clang-format JIT code (#35115) 2020-03-26 11:24:51 -07:00
python_arg_flatten.h
python_custom_class.cpp [JIT] Add Type::repr_str to return human-readable str (#39544) 2020-06-10 12:01:24 -07:00
python_custom_class.h
python_interpreter.cpp [JIT] clang-format JIT code (#35115) 2020-03-26 11:24:51 -07:00
python_ir.cpp [JIT] Add Type::repr_str to return human-readable str (#39544) 2020-06-10 12:01:24 -07:00
python_ir.h [JIT] clang-format JIT code (#35115) 2020-03-26 11:24:51 -07:00
python_ivalue.h Explicitly decref py::object in ConcretePyObjectHolder and PythonFunctionGuard (#38364) 2020-05-12 20:55:53 -07:00
python_sugared_value.cpp [JIT] Add Type::repr_str to return human-readable str (#39544) 2020-06-10 12:01:24 -07:00
python_sugared_value.h [JIT] Refactor attributes to support buffers and parameters as first class citizens, add support for iterating over named_buffers() (#37905) 2020-05-18 23:23:43 -07:00
python_tracer.cpp [jit] tracer flag to guard risky behaivors (#36277) 2020-04-13 22:35:03 -07:00
python_tracer.h [jit] tracer flag to guard risky behaivors (#36277) 2020-04-13 22:35:03 -07:00
python_tree_views.cpp [JIT] clang-format JIT code (#35115) 2020-03-26 11:24:51 -07:00
python_tree_views.h [jit] kill script namespace (#34515) 2020-03-11 23:32:48 -07:00
script_init.cpp Add CHECK-SOURCE-HIGHLIGHTED to file check utils. (#39692) 2020-06-11 23:47:07 -07:00
script_init.h [jit] kill script namespace (#34515) 2020-03-11 23:32:48 -07:00
update_graph_executor_opt.cpp Canonicalize includes in torch, and add tests for it (#36303) 2020-04-23 08:09:21 -07:00
update_graph_executor_opt.h [JIT] clang-format JIT code (#35115) 2020-03-26 11:24:51 -07:00