예제 #1
0
def save_click(input_1, v):
    """Action when clicking on the save button."""
    output_filename = fd.asksaveasfilename()
    input_filename = input_1.get()
    try:
        jk.convert_file(input_filename, output_filename, colormap=v.get())
    except AttributeError as e:
        print("Error 3:", e, file=sys.stderr)
    except ValueError as e:
        print("Error 4:", e, file=sys.stderr)
        tkinter.messagebox.showerror(
            "Format error", "Cannot save to file '{}' because the format is "
            "not unsupported.".format(output_filename))
    except FileNotFoundError as e:
        print("Error 5:", e, file=sys.stderr)
        tkinter.messagebox.showerror(
            "Conversion error",
            "Cannot convert file '{}' because it does not exist.".format(
                input_filename))
    except PermissionError as e:
        print("Error 6:", e, file=sys.stderr)
        tkinter.messagebox.showerror(
            "Save error",
            "Cannot save to file '{}' because of insufficient permissions. "
            "The file might be write-protected.".format(output_filename))
예제 #2
0
def test_convert_file_7():
    """Wrong input type"""
    with pytest.raises(Exception):
        jetkiller.convert_file("tests/test_data/generate_test_images.py",
                               "tests/test_data/protected_output_file.png")
예제 #3
0
def test_convert_file_8():
    """File not found."""
    with pytest.raises(Exception) as e:
        jetkiller.convert_file("tests/test_data/not_existing.png",
                               "tests/test_data/protected_output_file.png")
    assert e.type == FileNotFoundError
예제 #4
0
def test_convert_file_1():
    """2 args, no colormap."""
    jetkiller.convert_file("tests/test_data/test_input_1.png",
                           "tests/test_data/test_result_1.png")
    assert True
예제 #5
0
def test_convert_file_6():
    """Protected output."""
    with pytest.raises(Exception) as e:
        jetkiller.convert_file("tests/test_data/test_input_1.png",
                               "tests/test_data/protected_output_file.png")
    assert e.type == PermissionError
예제 #6
0
def test_convert_file_5():
    """1 arg, other colormap."""
    jetkiller.convert_file("tests/test_data/test_input_1.png",
                           colormap="magma")
    assert True
예제 #7
0
def test_convert_file_4():
    """1 arg, wrong colormap."""
    with pytest.raises(Exception) as e:
        jetkiller.convert_file("tests/test_data/test_input_1.png",
                               colormap="blabla")
    assert e.type == ValueError
예제 #8
0
def test_convert_file_3():
    """1 arg, no colormap."""
    jetkiller.convert_file("tests/test_data/test_input_1.png")
    assert True