|
| 1 | +# -*- mode: python -*- |
| 2 | +# vi: set ft=python : |
| 3 | + |
| 4 | +# Copyright (C) 2024 The C++ Plus Project. |
| 5 | +# This file is part of the Rubisco. |
| 6 | +# |
| 7 | +# Rubisco is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License as published |
| 9 | +# by the Free Software Foundation, either version 3 of the License, |
| 10 | +# or (at your option) any later version. |
| 11 | +# |
| 12 | +# Rubisco is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | +"""Test rubisco.kernel.command_event.event_types module. |
| 21 | +
|
| 22 | +This is a unittest generated by GitHub Copilot (Claude Sonnet 4), which is |
| 23 | +totally useless. If somebody see this file, please close it immediately, or |
| 24 | +create a issue or pull request to remove this file. |
| 25 | +""" |
| 26 | + |
| 27 | +from typing import Any |
| 28 | + |
| 29 | +import pytest |
| 30 | + |
| 31 | +from rubisco.kernel.command_event.callback import EventCallback |
| 32 | +from rubisco.kernel.command_event.event_types import ( |
| 33 | + EventObjectStat, |
| 34 | + EventObjectType, |
| 35 | +) |
| 36 | + |
| 37 | + |
| 38 | +class TestEventObjectStat: |
| 39 | + """Test EventObjectStat dataclass.""" |
| 40 | + |
| 41 | + def test_event_object_stat_creation(self) -> None: |
| 42 | + """Test EventObjectStat creation.""" |
| 43 | + |
| 44 | + def dummy_callback( |
| 45 | + options: list[Any], |
| 46 | + args: list[Any], |
| 47 | + ) -> None: |
| 48 | + del options |
| 49 | + del args |
| 50 | + |
| 51 | + callback = EventCallback(callback=dummy_callback, description="test") |
| 52 | + |
| 53 | + stat = EventObjectStat( |
| 54 | + type=EventObjectType.FILE, |
| 55 | + description="Test file", |
| 56 | + dir_callbacks=[callback], |
| 57 | + ) |
| 58 | + |
| 59 | + if stat.type != EventObjectType.FILE: |
| 60 | + pytest.fail("stat.type` should be FILE.") |
| 61 | + if stat.description != "Test file": |
| 62 | + pytest.fail("`stat.description` should be 'Test file'.") |
| 63 | + if len(stat.dir_callbacks) != 1: |
| 64 | + pytest.fail("`stat.dir_callbacks` should have one callback.") |
| 65 | + |
| 66 | + def test_event_object_stat_defaults(self) -> None: |
| 67 | + """Test EventObjectStat with default values.""" |
| 68 | + stat = EventObjectStat( |
| 69 | + type=EventObjectType.DIRECTORY, |
| 70 | + description="Test directory", |
| 71 | + ) |
| 72 | + |
| 73 | + if stat.type != EventObjectType.DIRECTORY: |
| 74 | + pytest.fail("`stat.type` should be `DIRECTORY`.") |
| 75 | + if stat.description != "Test directory": |
| 76 | + pytest.fail("`stat.description` should be 'Test directory'.") |
| 77 | + |
| 78 | + def test_event_object_stat_with_alias(self) -> None: |
| 79 | + """Test EventObjectStat with alias type.""" |
| 80 | + stat = EventObjectStat( |
| 81 | + type=EventObjectType.ALIAS, |
| 82 | + description="Test alias", |
| 83 | + alias_to="/some/path", |
| 84 | + ) |
| 85 | + |
| 86 | + if stat.type != EventObjectType.ALIAS: |
| 87 | + pytest.fail("stat.type should be ALIAS") |
| 88 | + if stat.description != "Test alias": |
| 89 | + pytest.fail("stat.description should be 'Test alias'") |
| 90 | + if str(stat.alias_to) != "/some/path": |
| 91 | + pytest.fail("stat.alias_to should be '/some/path'") |
| 92 | + |
| 93 | + def test_event_object_stat_with_mount_point(self) -> None: |
| 94 | + """Test EventObjectStat with mount point type.""" |
| 95 | + stat = EventObjectStat( |
| 96 | + type=EventObjectType.MOUNT_POINT, |
| 97 | + description="Test mount point", |
| 98 | + mount_to="/bin/ls", |
| 99 | + ) |
| 100 | + |
| 101 | + if stat.type != EventObjectType.MOUNT_POINT: |
| 102 | + pytest.fail("`stat.type` should be `MOUNT_POINT`.") |
| 103 | + if stat.description != "Test mount point": |
| 104 | + pytest.fail("`stat.description` should be 'Test mount point'.") |
| 105 | + if stat.mount_to != "/bin/ls": |
| 106 | + pytest.fail("`stat.mount_to` should be '/bin/ls'") |
| 107 | + |
| 108 | + def test_event_object_stat_alias_validation(self) -> None: |
| 109 | + """Test EventObjectStat alias validation.""" |
| 110 | + with pytest.raises(ValueError, match="Alias must have an alias_to"): |
| 111 | + EventObjectStat( |
| 112 | + type=EventObjectType.ALIAS, |
| 113 | + description="Test alias without alias_to", |
| 114 | + ) |
0 commit comments