def test_version(capsys):
    from ttblit import main, __version__

    with pytest.raises(SystemExit):
        main(['version'])

    assert capsys.readouterr().out == f'{__version__}\n'
def test_image_png_cli_strict_nopalette(test_input_file):
    from ttblit import main

    with pytest.raises(TypeError):
        main([
            'image', '--input_file', test_input_file.name, '--output_format',
            'c_header', '--strict'
        ])
def test_image_png_cli_packed(test_input_file):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'image', '--input_file', test_input_file.name, '--packed',
            '--output_format', 'c_header'
        ])
def test_map_tiled_cli(test_input_file):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'map', '--input_file', test_input_file.name, '--output_format',
            'c_header'
        ])
Beispiel #5
0
def test_cmake_asset(test_asset_config_file, test_cmake_file):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'cmake', '--config', test_asset_config_file.name, '--cmake',
            test_cmake_file.name
        ])
def test_relocs(test_input_bin, test_input_elf, test_output_file):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'relocs', '--bin-file', test_input_bin.name, '--elf-file',
            test_input_elf.name, '--output', test_output_file.name
        ])
Beispiel #7
0
def test_metadata_invalid_bin(test_resources, test_invalid_binary_file):
    from ttblit import main

    with pytest.raises(ValueError):
        main([
            'metadata', '--config',
            str(test_resources / 'metadata-basic.yml'), '--file',
            test_invalid_binary_file.name
        ])
Beispiel #8
0
def test_metadata_file_associations(test_resources, test_binary_file):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'metadata', '--config',
            str(test_resources / 'metadata-file-associations.yml'), '--file',
            test_binary_file.name
        ])
def test_packer_cli_invalid_input(test_resources, output_dir):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'pack', '--force', '--config',
            str(test_resources / 'assets_invalid_input.yml'), '--output',
            output_dir
        ])
def test_packer_cli_relative_yml(test_resources, output_dir):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'pack', '--force', '--config',
            str(test_resources / 'assets_relative.yml'), '--output', output_dir
        ])

    assert (pathlib.Path(output_dir) / "assets.hpp").exists()
    assert (pathlib.Path(output_dir) / "assets.cpp").exists()
Beispiel #11
0
def test_cmake_no_depends(test_empty_metadata_file, test_cmake_file):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'cmake', '--config', test_empty_metadata_file.name, '--cmake',
            test_cmake_file.name
        ])

    assert open(test_cmake_file.name).read().replace(
        '    ', '') == '''# Auto Generated File - DO NOT EDIT!
Beispiel #12
0
def test_cmake_multiple_outputs(test_resources, test_cmake_file):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'cmake', '--config',
            str(test_resources / 'assets_multi_out.yml'), '--cmake',
            test_cmake_file.name
        ])

    assert open(test_cmake_file.name).read().startswith(
        '# Auto Generated File - DO NOT EDIT!')
Beispiel #13
0
def test_metadata_icns(test_resources, test_binary_file, test_icns_file):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'metadata', '--config',
            str(test_resources / 'metadata-basic.yml'), '--file',
            test_binary_file.name, '--icns', test_icns_file.name, '--force'
        ])

    test_icns_file.flush()
    assert test_icns_file.read()[:4] == b'icns'
Beispiel #14
0
def test_cmake(test_metadata_file, test_cmake_file):
    from ttblit import main

    test_metadata_file, test_metadata_splash_png = test_metadata_file

    with pytest.raises(SystemExit):
        main([
            'cmake', '--config', test_metadata_file.name, '--cmake',
            test_cmake_file.name
        ])

    assert open(test_cmake_file.name).read().startswith(
        '# Auto Generated File - DO NOT EDIT!')
def test_image_png_cli_strict_palette_pal_missing(test_input_file):
    from ttblit import main

    with tempfile.NamedTemporaryFile('wb', suffix='.pal') as test_palette_file:
        test_palette_file.write(b'\x00\x00\x00')  # Write black colour
        test_palette_file.write(b'\xff\xff\xff')  # Write white colour
        test_palette_file.write(b'\x00' * (768 - 6))  # Pad to 768 bytes
        test_palette_file.flush()
        with pytest.raises(TypeError):
            main([
                'image', '--input_file', test_input_file.name,
                '--output_format', 'c_header', '--strict', '--palette',
                test_palette_file.name
            ])
def test_image_png_cli_packed_blank():
    from ttblit import main

    with tempfile.NamedTemporaryFile('wb', suffix='.png') as temp_png:
        # this is a solid white image
        temp_png.write(
            base64.b64decode(
                b'iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TxQ8qDq0g4pChOlkQFXHUKhShQqgVWnUwufQLmjQkKS6OgmvBwY/FqoOLs64OroIg+AHi5Oik6CIl/i8ptIjx4Lgf7+497t4BQr3MNKtjHNB020wl4mImuyp2vaIHAwhDRFhmljEnSUn4jq97BPh6F+NZ/uf+HH1qzmJAQCSeZYZpE28QT2/aBud94ggryirxOfGYSRckfuS64vEb54LLAs+MmOnUPHGEWCy0sdLGrGhqxFPEUVXTKV/IeKxy3uKslauseU/+wlBOX1nmOs1hJLCIJUjUkYIqSijDRoxWnRQLKdqP+/iHXL9ELoVcJTByLKACDbLrB/+D391a+ckJLykUBzpfHOdjBOjaBRo1x/k+dpzGCRB8Bq70lr9SB2Y+Sa+1tOgR0L8NXFy3NGUPuNwBBp8M2ZRdKUhTyOeB9zP6piwQvgV617zemvs4fQDS1FXyBjg4BEYLlL3u8+7u9t7+PdPs7wdkRXKhyqpX4AAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+QJFRQDAWzTXhEAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAFUlEQVQI12P8//8/AzbAxIADDE4JAFbUAw1h62h+AAAAAElFTkSuQmCC'
            ))
        temp_png.flush()

        with pytest.raises(SystemExit):
            main([
                'image', '--input_file', temp_png.name, '--packed',
                '--output_format', 'c_header'
            ])
def test_packer_cli_file_missing(test_resources, output_dir):
    from ttblit import main

    with pytest.raises(RuntimeError):
        main([
            'pack', '--force', '--config',
            str(test_resources / 'assets_file_missing.yml'), '--output',
            output_dir
        ])

    with pytest.raises(RuntimeError):
        main([
            'pack', '--force', '--config',
            str(test_resources / 'assets_one_file_missing.yml'), '--output',
            output_dir
        ])
def test_image_png_cli_packed_multi_transparent():
    from ttblit import main

    with tempfile.NamedTemporaryFile('wb', suffix='.png') as temp_png:
        # many colours with alpha 0
        temp_png.write(
            base64.b64decode(
                b'iVBORw0KGgoAAAANSUhEUgAAAIAAAAAICAYAAAAx3fd+AAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV9TxQ8qDq0g4pChOlkQFXHUKhShQqgVWnUwufQLmjQkKS6OgmvBwY/FqoOLs64OroIg+AHi5Oik6CIl/i8ptIjx4Lgf7+497t4BQr3MNKtjHNB020wl4mImuyp2vaIHAwhDRFhmljEnSUn4jq97BPh6F+NZ/uf+HH1qzmJAQCSeZYZpE28QT2/aBud94ggryirxOfGYSRckfuS64vEb54LLAs+MmOnUPHGEWCy0sdLGrGhqxFPEUVXTKV/IeKxy3uKslauseU/+wlBOX1nmOs1hJLCIJUjUkYIqSijDRoxWnRQLKdqP+/iHXL9ELoVcJTByLKACDbLrB/+D391a+ckJLykUBzpfHOdjBOjaBRo1x/k+dpzGCRB8Bq70lr9SB2Y+Sa+1tOgR0L8NXFy3NGUPuNwBBp8M2ZRdKUhTyOeB9zP6piwQvgV617zemvs4fQDS1FXyBjg4BEYLlL3u8+7u9t7+PdPs7wdkRXKhyqpX4AAAAAZiS0dEAAAAAAD/1EFU8gAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+QJFRQALXUmYTEAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAACKUlEQVRYw71X7ZLjMAiTYN//jXd0P/yFCU7SvbvtDOPWgBCGxJQkYWYfCmHm+x4N5mcfmsEr/we/5Tt8li+73iMHM9DHHkHzENdAEu4+eZBL5zOWg86JZ+YbR6eBFs7NQx5cOFO3+fXvbmC2zRws1cYXRvbL8qQf8gUJ+P5u8vDRBzqllQ/+JywBsGIPAXfs6QZvCB8wmOxOeJb27uwz/ikWX3BQgVXlf9Jfbdiz+Q0hAP8L/b+IO/L1g92dzov1rd9TnKoOXvgz6SocP3AuYhM/7oBPq/UT+7tT8B+c8l1V86laUXH7Zfn/cb9IwGwJDXADzFTsReHVj4J5tlv2EyfaEfN70yvg84C1OLWVBUfuMQ2gCT7yHTEpuDc7M8HIpiNgPn73teDhA4sAh5+dZXC+O8tlo35XB84P+CfMIwaOd1n8psdJgABAlpeWAEDFrSsB3OeE5qKbW7QtjGvmqHVTrtlDoAgR01ndWwNr4nK+G1c89vS4pxDv1pnICNJ8tmMhj1MDyxPWxuPt5MHTRJS27d1Yxiu0Tu2gehIhFwpH8VmkwT6YqIDkOkTtfbSZkn2PwWwVVav3GgW1mEpdKy3OokI7ra4l2P2RGrCJlAYvoR4JJ2TsvHwSfD2Wvx247SPr7WlPk6aK3uP+lO4grAmrSJbXt4JC4PhkzhJNftrAJfXCs//upacSLgAq5diSIRWKc/3/wdvntHqbcuPIyPcyy3/w9+PF5w8xhbP1sQP9IwAAAABJRU5ErkJggg=='
            ))
        temp_png.flush()

        with pytest.raises(SystemExit):
            main([
                'image', '--input_file', temp_png.name, '--packed',
                '--output_format', 'c_header'
            ])
def test_image_png_cli_strict_palette_act(test_input_file):
    from ttblit import main

    with tempfile.NamedTemporaryFile('wb', suffix='.act') as test_palette_file:
        test_palette_file.write(b'\x00\x00\x00')  # Write black colour
        test_palette_file.write(b'\x00\xff\x00')  # Write green colour
        test_palette_file.write(b'\xff\xff\xff')  # Write white colour
        test_palette_file.write(b'\x00' * 759)  # Pad to 772 bytes
        test_palette_file.write(b'\x00\x03')  # Write size
        test_palette_file.write(b'\x00\x00')  # Ignored bytes
        test_palette_file.flush()
        with pytest.raises(SystemExit):
            main([
                'image', '--input_file', test_input_file.name,
                '--output_format', 'c_header', '--strict', '--palette',
                test_palette_file.name
            ])
def test_packer_cli_wildcard_default(test_resources, output_dir):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'pack', '--force', '--config',
            str(test_resources / 'assets_wildcard_default.yml'), '--output',
            output_dir
        ])

    assert (pathlib.Path(output_dir) / "assets.hpp").exists()
    assert (pathlib.Path(output_dir) / "assets.cpp").exists()

    hpp = open(pathlib.Path(output_dir) / "assets.hpp", "r").read()

    assert "asset_level_01_tmx" in hpp
    assert "asset_level_02_tmx" in hpp
def test_packer_cli_multiple_outputs(test_resources, output_dir):
    from ttblit import main

    with pytest.raises(SystemExit):
        main([
            'pack', '--force', '--config',
            str(test_resources / 'assets_multi_out.yml'), '--output',
            output_dir
        ])

    assert (pathlib.Path(output_dir) / "assets.hpp").exists()
    assert (pathlib.Path(output_dir) / "assets.cpp").exists()

    hpp = open(pathlib.Path(output_dir) / "assets.hpp", "r").read()

    assert "asset_image_packed" in hpp
    assert "asset_image_raw" in hpp
def test_image_png_cli_strict_palette_pal_transparent(test_input_file):
    from ttblit import main

    with tempfile.NamedTemporaryFile('wb', suffix='.pal') as test_palette_file:
        test_palette_file.write(b'\x00\x00\x00')  # Write black colour
        test_palette_file.write(b'\x00\xff\x00')  # Write green colour
        test_palette_file.write(b'\xff\xff\xff')  # Write white colour
        test_palette_file.write(b'\x00' * (768 - 9))  # Pad to 768 bytes
        test_palette_file.flush()

        with pytest.raises(SystemExit):
            main([
                'image', '--input_file', test_input_file.name,
                '--output_format', 'c_header', '--strict', '--palette',
                test_palette_file.name, '--transparent', '0,255,0'
            ])  # Make green transparent

        with pytest.raises(SystemExit):
            main([
                'image', '--input_file', test_input_file.name,
                '--output_format', 'c_header', '--strict', '--palette',
                test_palette_file.name, '--transparent', '88,88,88'
            ])  # Invalid colour
Beispiel #23
0
def test_metadata_no_args():
    from ttblit import main

    with pytest.raises(SystemExit):
        main(['metadata'])
def test_map_tiled_cli_no_args():
    from ttblit import main

    with pytest.raises(SystemExit):
        main(['map'])
Beispiel #25
0
def test_cmake_no_args():
    from ttblit import main

    with pytest.raises(SystemExit):
        main(['cmake'])
def test_packer_cli_no_args():
    from ttblit import main

    with pytest.raises(SystemExit):
        main(['pack'])
def test_image_png_cli_no_args():
    from ttblit import main

    with pytest.raises(SystemExit):
        main(['image'])