def test_exactdiff_handles_second_file_not_found(tmp_path: pathlib2.Path):
    onefile = tmp_path / 'something.json'
    onefile.touch(exist_ok=False)
    with pytest.raises(FileNotFoundError) as file_not_found_error:
        inspect_compute_results.main_helper(
            ['exactdiff', str(onefile), 'nofile.json'])
    assert 'FileNotFoundError: Input file "nofile.json" not found' in str(
        file_not_found_error)
def check_diff(tmp_path: pathlib2.Path,
               output1: str,
               output2: str,
               is_exact: bool,
               extra_args: Optional[List[str]] = None) -> int:
    results1_path = tmp_path / '1.info.json'
    results2_path = tmp_path / '2.info.json'
    with results1_path.open(mode='w') as results1_file:
        results1_file.write(output1)
    with results2_path.open(mode='w') as results2_file:
        results2_file.write(output2)
    args = [
        'exactdiff' if is_exact else 'fuzzydiff',
        str(results1_path),
        str(results2_path)
    ]
    if extra_args:
        args += extra_args
    return inspect_compute_results.main_helper(args)
def test_show_handles_file_not_found(tmp_path: pathlib2.Path):
    with pytest.raises(FileNotFoundError) as file_not_found_error:
        inspect_compute_results.main_helper(['show', 'nofile.json'])
    assert 'FileNotFoundError: Input file "nofile.json" not found' in str(
        file_not_found_error)
def test_fuzzydiff_rejects_three_args(tmp_path: pathlib2.Path):
    with pytest.raises(ValueError) as value_error:
        inspect_compute_results.main_helper(
            ['fuzzydiff', '1.json', '2.json', '3.json'])
    assert 'ValueError: Command "fuzzydiff" requires exactly 2 inputs; 3 provided' in str(
        value_error)
def test_exactdiff_rejects_one_arg(tmp_path: pathlib2.Path):
    with pytest.raises(ValueError) as value_error:
        inspect_compute_results.main_helper(['exactdiff', '1.json'])
    assert 'ValueError: Command "exactdiff" requires exactly 2 inputs; 1 provided' in str(
        value_error)
def test_bad_abs_tol2():
    with pytest.raises(ValueError) as value_error:
        inspect_compute_results.main_helper(
            ['fuzzydiff', '1.json', '2.json', '--abs_tol=-0.1'])
    assert 'ValueError: Non-negative floating-point value required for --abs_tol argument'\
           in str(value_error)
def test_bad_rel_tol():
    with pytest.raises(ValueError) as value_error:
        inspect_compute_results.main_helper(
            ['fuzzydiff', '1.json', '2.json', '--rel_tol=notafloat'])
    assert 'ValueError: Positive floating-point value required for --rel_tol argument'\
           in str(value_error)
def test_show_rejects_multiple_args(tmp_path: pathlib2.Path):
    with pytest.raises(ValueError) as value_error:
        inspect_compute_results.main_helper(['show', '1.json', '2.json'])
    assert 'ValueError: Command "show" requires exactly 1 input; 2 provided' in str(
        value_error)
def test_unknown_command_rejected(tmp_path: pathlib2.Path):
    with pytest.raises(ValueError) as value_error:
        inspect_compute_results.main_helper(['unknown', '1.json', '2.json'])
    assert 'ValueError: Unknown command' in str(value_error)
#!/usr/bin/env python3

# Copyright 2019 The GraphicsFuzz Project Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import inspect_compute_results
import sys

try:
    sys.exit(inspect_compute_results.main_helper(sys.argv[1:]))
except ValueError as value_error:
    sys.stderr.write(str(value_error))
    sys.exit(1)