コード例 #1
0
def test_CursorAlias_create_with_static_bitmap_and_single_size(
        static_bitmap, static_png) -> None:
    """Testing CursorAlias create method with single pixel size and static bitmap."""
    alias = CursorAlias(static_bitmap)

    assert len(sorted(alias.alias_dir.iterdir())) == 0
    alias.create((10, 10), delay=999999)

    for file in alias.alias_dir.iterdir():
        if file.is_dir():
            alias_png = list(file.iterdir())[0]
            assert static_png.name == alias_png.name
            i = Image.open(alias_png)
            assert i.size == (10, 10)
            i.close()
        else:
            assert file.stem == static_bitmap.key

            with file.open("r") as f:
                assert f.readlines() == ["10 0 0 10x10/test-0.png"]

    files = [f.name for f in alias.alias_dir.glob("**/*")]
    assert sorted(files) == sorted(["10x10", "test-0.alias", "test-0.png"])

    shutil.rmtree(alias.alias_dir)
コード例 #2
0
def test_CursorAlias_rename_with_animated_bitmap(image_dir) -> None:
    """Testing CursorAlias rename method with animated bitmap."""
    animated_bitmap = Bitmap(create_test_image(image_dir, 4), (0, 0))
    alias = CursorAlias(animated_bitmap)
    alias.create((10, 10))

    old_alias = alias
    alias.rename("test_key")

    assert alias.prefix == "test_key__alias"
    assert (sorted(
        filter(lambda x: x.is_file is True,
               old_alias.alias_dir.glob("*/**"))) == [])

    assert file_tree(alias) == [
        "10x10",
        "test_key-0.png",
        "test_key-1.png",
        "test_key-2.png",
        "test_key-3.png",
        "test_key.alias",
    ]

    with alias.alias_file.open("r") as f:
        assert f.readlines() == [
            "10 0 0 10x10/test_key-0.png 10\n",
            "10 0 0 10x10/test_key-1.png 10\n",
            "10 0 0 10x10/test_key-2.png 10\n",
            "10 0 0 10x10/test_key-3.png 10",
        ]

    shutil.rmtree(alias.alias_dir)
コード例 #3
0
def test_CursorAlias_copy_with_animated_bitmap_without_args(
        animated_bitmap) -> None:
    """Testing CursorAlias copy method with animated bitmap without any arguments."""
    alias = CursorAlias(animated_bitmap)
    alias.create((10, 10))
    copy_of_alias = alias.copy()

    check_alias_copy(alias, copy_of_alias)

    shutil.rmtree(alias.alias_dir)
コード例 #4
0
def test_CursorAlias_copy_with_animated_bitmap_with_args(
        animated_bitmap) -> None:
    """Testing CursorAlias copy method with animated bitmap with any arguments."""
    alias = CursorAlias(animated_bitmap)
    alias.create((10, 10))
    param_dst = Path(tempfile.mkdtemp())
    copy_of_alias = alias.copy(param_dst)

    check_alias_copy(alias, copy_of_alias, param_dst=str(param_dst.absolute()))

    shutil.rmtree(alias.alias_dir)
コード例 #5
0
def test_CursorAlias_copy_path_not_directory_exception(static_bitmap,
                                                       test_file) -> None:
    """Testing CursorAlias copy method ``NotADirectoryError`` (provided path is not a directory) exception."""
    alias = CursorAlias(static_bitmap)
    alias.create((10, 10))
    with pytest.raises(NotADirectoryError) as excinfo:
        alias.copy(test_file)
    assert str(
        excinfo.value) == f"path '{test_file.absolute()}' is not a directory"

    shutil.rmtree(alias.alias_dir)
コード例 #6
0
def test_CursorAlias_extension(static_bitmap) -> None:
    """Testing CursorAlias ``extension`` method."""
    alias = CursorAlias(static_bitmap)
    alias.create((10, 10))
    assert alias.alias_file.suffix == ".alias"
    assert alias.extension() == ".alias"
    alias.extension(".test")
    assert alias.alias_file.suffix == ".test"
    assert alias.extension() == ".test"

    shutil.rmtree(alias.alias_dir)
コード例 #7
0
def test_static_CursorAlias_repr(static_bitmap):
    """Testing CursorAlias ``__repr__`` datamethod."""
    alias = CursorAlias(static_bitmap)
    assert (
        alias.__repr__() ==
        f"{{ 'bitmap':{static_bitmap!r}, 'prefix':{alias.prefix}, 'alias_dir':{alias.alias_dir}, 'alias_file':None, 'garbage_dirs':[] }}"
    )
    alias.create((10, 10))
    assert (
        alias.__repr__() ==
        f"{{ 'bitmap':{static_bitmap!r}, 'prefix':{alias.prefix}, 'alias_dir':{alias.alias_dir}, 'alias_file':{alias.alias_file}, 'garbage_dirs':[] }}"
    )
    shutil.rmtree(alias.alias_dir)
コード例 #8
0
def test_static_CursorAlias_str(static_bitmap):
    """Testing CursorAlias ``__str__`` datamethod."""
    alias = CursorAlias(static_bitmap)
    assert (
        alias.__str__() ==
        f"CursorAlias(bitmap={static_bitmap!s}, prefix={alias.prefix}, alias_dir={alias.alias_dir}, alias_file=None, garbage_dirs=[])"
    )
    alias.create((10, 10))
    assert (
        alias.__str__() ==
        f"CursorAlias(bitmap={static_bitmap!s}, prefix={alias.prefix}, alias_dir={alias.alias_dir}, alias_file={alias.alias_file}, garbage_dirs=[])"
    )

    shutil.rmtree(alias.alias_dir)
コード例 #9
0
ファイル: conftest.py プロジェクト: ful1e5/clickgen
def animated_config(animated_bitmap):
    """Mock animated cursor config file."""

    alias = CursorAlias(animated_bitmap)
    yield alias.create((10, 10))

    shutil.rmtree(alias.alias_dir)
コード例 #10
0
def test_CursorAlias_rename_with_static_bitmap(static_bitmap) -> None:
    """Testing CursorAlias rename method with static bitmap."""
    alias = CursorAlias(static_bitmap)
    alias.create((10, 10))

    old_alias = alias
    alias.rename("test_key")

    assert alias.prefix == "test_key__alias"
    assert (sorted(
        filter(lambda x: x.is_file is True,
               old_alias.alias_dir.glob("*/**"))) == [])

    assert file_tree(alias) == ["10x10", "test_key.alias", "test_key.png"]

    with alias.alias_file.open("r") as f:
        assert f.readlines() == ["10 0 0 10x10/test_key.png"]

    shutil.rmtree(alias.alias_dir)
コード例 #11
0
def test_CursorAlias_check_alias(static_bitmap, animated_bitmap) -> None:
    """Testing CursorAlias ``check_alias`` method."""
    alias = CursorAlias(static_bitmap)

    with pytest.raises(FileNotFoundError) as excinfo:
        alias.check_alias()
    assert str(excinfo.value) == alias_not_exists_err

    alias.create((10, 10))
    alias.check_alias()

    animated_alias = CursorAlias(animated_bitmap)
    with pytest.raises(FileNotFoundError) as excinfo:
        animated_alias.check_alias()
    assert str(excinfo.value) == alias_not_exists_err

    animated_alias.create((10, 10))
    animated_alias.check_alias()

    shutil.rmtree(alias.alias_dir)
コード例 #12
0
def test_CursorAlias_create_type_error_exception(mock_sizes,
                                                 static_bitmap) -> None:
    """Testing CursorAlias create method ``TypeError`` exception."""
    alias = CursorAlias(static_bitmap)
    with pytest.raises(TypeError) as excinfo:
        assert alias.create(sizes=mock_sizes)
    assert (
        str(excinfo.value) ==
        "argument 'sizes' should be Tuple[int, int] type or List[Tuple[int, int]]."
    )
    shutil.rmtree(alias.alias_dir)
コード例 #13
0
def test_CursorAlias_create_with_animated_bitmap_and_single_size(
        image_dir) -> None:
    """Testing CursorAlias create method with single pixel size and animated bitmap."""
    animated_png = create_test_image(image_dir, 4)
    animated_bitmap = Bitmap(animated_png, (13, 6))
    alias = CursorAlias(animated_bitmap)

    assert len(sorted(alias.alias_dir.iterdir())) == 0
    alias.create((10, 10), delay=999999)

    def as_list(frames: List[Path]) -> List[str]:
        return sorted(map(lambda x: x.stem, frames))

    for file in alias.alias_dir.iterdir():
        if file.is_dir():
            frames = list(file.iterdir())
            assert as_list(frames) == as_list(animated_png)
        else:
            assert file.stem == animated_bitmap.key

            with file.open("r") as f:
                assert f.readlines() == [
                    "10 6 3 10x10/test-0.png 999999\n",
                    "10 6 3 10x10/test-1.png 999999\n",
                    "10 6 3 10x10/test-2.png 999999\n",
                    "10 6 3 10x10/test-3.png 999999",
                ]

    files = []
    for f in alias.alias_dir.glob("**/*"):
        files.append(f.name)

    assert sorted(files) == sorted([
        "10x10", "test-0.png", "test-1.png", "test-2.png", "test-3.png",
        "test.alias"
    ])

    shutil.rmtree(alias.alias_dir)
コード例 #14
0
def test_CursorAlias_create_with_static_bitmap_and_multiple_size(
        static_png) -> None:
    """Testing CursorAlias create method with multiple pixel size and static bitmap."""
    static_bitmap = Bitmap(static_png, (9, 13))
    mock_sizes = [(10, 10), (15, 15), (16, 16)]
    alias = CursorAlias(static_bitmap)

    assert len(sorted(alias.alias_dir.iterdir())) == 0
    alias.create(mock_sizes, delay=99999)

    for file in alias.alias_dir.iterdir():
        if file.is_dir():
            alias_png = list(file.iterdir())[0]
            assert static_png.name == alias_png.name
            i = Image.open(alias_png)
            assert i.size in mock_sizes
            i.close()
        else:
            assert file.stem == static_bitmap.key

            with file.open("r") as f:
                assert f.readlines() == [
                    "10 4 6 10x10/test-0.png\n",
                    "15 7 10 15x15/test-0.png\n",
                    "16 7 10 16x16/test-0.png",
                ]

    files = [f.name for f in alias.alias_dir.glob("**/*")]
    assert sorted(files) == sorted([
        "10x10",
        "15x15",
        "16x16",
        "test-0.alias",
        "test-0.png",  # Because it's generate 3 size of png in individual directory.
        "test-0.png",
        "test-0.png",
    ])
    shutil.rmtree(alias.alias_dir)
コード例 #15
0
ファイル: conftest.py プロジェクト: ful1e5/clickgen
def static_config(static_bitmap):
    """Mock static cursor config file."""
    alias = CursorAlias(static_bitmap)
    yield alias.create((10, 10))

    shutil.rmtree(alias.alias_dir)