Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch bogus Excluding Merge-Ins
This is equivalent to a diff from 7fd2678252 to 1d17856aa5
|
2025-10-05
| ||
| 16:01 | Fixed crash when trying to switch the printing o a card. This was caused by a double signal connection, applying the same DocumentAction twice. Fixes [4ddeb969368396ad] check-in: b0fb2950a9 user: thomas tags: trunk | |
| 11:51 | Patch Qt.ConnectionType: Add an __or__(other: ConnectionType) implementation that allows combining Qt ConnectionType items as stated by the Qt documentation. check-in: c5969183c1 user: thomas tags: prevent_duplicate_connections | |
|
2025-10-02
| ||
| 16:35 | Implemented moving cards around via drag&drop. Implements [851b0af285008db4], [fb4ed046b020652d]. Closed-Leaf check-in: 1d17856aa5 user: thomas tags: bogus | |
| 16:35 | Updated changelog entry. check-in: f65e828585 user: thomas tags: drag_drop_move_cards | |
|
2025-09-25
| ||
| 20:43 | Merge with trunk, importing crash fixes check-in: 7e2f3a4228 user: thomas tags: drag_drop_move_cards | |
| 20:40 | Restore connection between DocumentLoader.unknown_scryfall_ids_found signal and main_window.on_document_loading_found_unknown_scryfall_ids slot. check-in: 7fd2678252 user: thomas tags: trunk | |
| 20:33 | Fixed crash when loading a document containing a hidden printing without an available replacement. Fixes [9f34dd5d1d2f1ce3] check-in: ba1171e668 user: thomas tags: trunk | |
Changes to doc/changelog.md.
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | + + + + + + + | # Changelog # Next version (in development) # New features - Move cards around via drag&drop - Drop onto other pages to move cards to those pages - Drop cards between pages to move those cards onto a new page at that location - Re-order cards within a page # Fixed issues - Fixed crash when trying to load a document that contains a hidden printing that does not have an available replacement printing. - Restored reporting if hidden printings were migrated to available ones during document loading # Version 0.34.0 (2025-09-11) <a name="v0_34_0"></a> |
| ︙ |
Changes to mtg_proxy_printer/document_controller/compact_document.py.
| ︙ | |||
17 18 19 20 21 22 23 | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | - + | from PySide6.QtCore import QObject from mtg_proxy_printer.model.document import Document from mtg_proxy_printer.units_and_sizes import PageType from ._interface import DocumentAction, IllegalStateError, ActionList, Self from .page_actions import ActionRemovePage |
| ︙ | |||
79 80 81 82 83 84 85 | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | - + |
logger.debug(f"Found {cards_to_add} empty slots on page {current_index}")
while cards_to_add and current_index < last_index:
page_to_draw_from = document.pages[last_index]
if page_to_draw_from.page_type() is not page_type:
last_index -= 1
continue
cards_to_take = min(len(page_to_draw_from), cards_to_add)
|
| ︙ |
Changes to mtg_proxy_printer/document_controller/edit_document_settings.py.
| ︙ | |||
18 19 20 21 22 23 24 | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | - + | import itertools import typing from PySide6.QtCore import QObject from ._interface import DocumentAction, ActionList, Self, split_iterable from .card_actions import ActionRemoveCards |
| ︙ | |||
108 109 110 111 112 113 114 | 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | - + |
start_index = document.find_page_list_index(partition.pages[0])
end_index = start_index + partition.size()
page_capacity = document.page_layout.compute_page_card_capacity(partition.page_type)
# TODO: The algorithm currently isn't very optimized. This loop should insert new pages,
# if the excess exceeds some threshold.
for page_index, page in enumerate(partition.pages[:-1], start=start_index):
if (page_length := len(page)) > page_capacity:
|
| ︙ |
Changes to mtg_proxy_printer/document_controller/move_cards.py.
| ︙ | |||
8 9 10 11 12 13 14 | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | - + + - + + - + - + + + + + + + + - + + + + - - + | # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| ︙ | |||
108 109 110 111 112 113 114 | 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |
source_row_first = len(source_page) - self._total_moved_cards() if self.target_row is None else self.target_row
for target_row_first, target_row_last in self.card_ranges_to_move:
source_row_last = source_row_first + target_row_last - target_row_first
self._move_cards_to_target_page(
document, source_index, source_page, source_row_first, source_row_last, target_index,
target_page, target_row_first
)
|
Changes to mtg_proxy_printer/model/document.py.
| ︙ | |||
10 11 12 13 14 15 16 | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | - + + + - - + + + + + - - - - - - - - - - - + + + + + + + + | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| ︙ | |||
98 99 100 101 102 103 104 | 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | - - + + + + + + + |
PageColumns.Set: self.tr("Set"),
PageColumns.CollectorNumber: self.tr("Collector #"),
PageColumns.Language: self.tr("Language"),
PageColumns.Image: self.tr("Image"),
PageColumns.IsFront: self.tr("Side"),
}
|
| ︙ | |||
244 245 246 247 248 249 250 | 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | - - - - + + + + + + + + + |
def flags(self, index: AnyIndex) -> Qt.ItemFlag:
index = self._to_index(index)
data = index.internalPointer()
flags = super().flags(index)
if isinstance(data, CardContainer) and (index.column() in self.EDITABLE_COLUMNS or data.card.is_custom_card):
flags |= ItemFlag.ItemIsEditable
|
| ︙ | |||
285 286 287 288 289 290 291 | 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | + + + + + - - - - - + + + + + + + - - + + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + - - + + |
def _fetch_image_and_apply_action(self, action: SingleActions):
task = SingleDownloadTask(self.image_db, action)
task.request_action.connect(self.apply, BlockingQueuedConnection)
self.request_run_async_task.emit(task)
def mimeData(self, indexes: list[QModelIndex], /) -> QMimeData:
"""
Reads model data and converts them into QMimeData used for Drag&Drop.
Dragging a page encodes its initial position
Dragging cards encodes their shared page index, and a list of card indices.
"""
|
| ︙ | |||
374 375 376 377 378 379 380 | 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | - + |
return card.image_file
elif column == PageColumns.IsFront:
return card.is_front if role == ItemDataRole.EditRole else (
self.tr("Front") if card.is_front else self.tr("Back"))
return None
def _get_page_preview(self, page: Page):
|
| ︙ | |||
401 402 403 404 405 406 407 | 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | - + |
raise RuntimeError("Cannot save without a file path!")
ActionSaveDocument(self.save_file_path).apply(self) # Note: Not using the action stack. Saving cannot be undone
def compute_pages_saved_by_compacting(self) -> int:
"""
Computes the number of pages that can be saved by compacting the document.
"""
|
| ︙ |
Changes to mtg_proxy_printer/model/document_page.py.
| ︙ | |||
33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | + + + |
@dataclasses.dataclass
class CardContainer:
parent: "Page"
card: AnyCardType
def __repr__(self):
return f"{self.__class__.__name__}(card={self.card})"
class Page(list[CardContainer]):
def __init__(self, __iterable: Iterable[AnyCardType] = None):
__iterable = __iterable or []
__iterable = map(partial(CardContainer, self), __iterable)
super().__init__(__iterable)
|
| ︙ |
Changes to mtg_proxy_printer/page_scene/page_scene.py.
| ︙ | |||
359 360 361 362 363 364 365 | 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | - - - - - - - - - - + + |
def draw_card(self, index: QModelIndex, page_type: PageType, next_item: CardItem = None):
position = self._compute_position_for_image(index.row(), page_type)
if index.data(ItemDataRole.DisplayRole) is not None: # Card has a QPixmap set
card_item = CardItem(index, self.document)
self.addItem(card_item)
card_item.setPos(position)
|
| ︙ | |||
444 445 446 447 448 449 450 | 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 | + - + + + + + + + + + + + + - + - - + - - - - + + + |
self.update_card_positions()
self.update_card_bleeds()
elif not parent.isValid():
# Page removed. Update the page number text, as it contains the total number of pages
self._update_page_number_text()
def on_rows_moved(self, parent: QModelIndex, start: int, end: int, destination: QModelIndex, row: int):
source_page_row = parent.row()
|
| ︙ |
Changes to resources/ui/central_widget/columnar.ui.
| ︙ | |||
90 91 92 93 94 95 96 97 98 99 100 101 102 103 | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | + + + + + + |
</property>
<property name="contextMenuPolicy">
<enum>Qt::ContextMenuPolicy::CustomContextMenu</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDropMode::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::DropAction::MoveAction</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectionBehavior::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
|
| ︙ | |||
126 127 128 129 130 131 132 | 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | - + |
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="dragDropMode">
|
| ︙ |
Changes to resources/ui/central_widget/grouped.ui.
| ︙ | |||
36 37 38 39 40 41 42 | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | - + |
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>3</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="dragDropMode">
|
| ︙ | |||
128 129 130 131 132 133 134 135 136 137 138 139 140 141 | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | + + + + + + |
</property>
<property name="contextMenuPolicy">
<enum>Qt::ContextMenuPolicy::CustomContextMenu</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDropMode::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::DropAction::MoveAction</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectionBehavior::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
|
| ︙ |
Changes to resources/ui/central_widget/tabbed_vertical.ui.
| ︙ | |||
70 71 72 73 74 75 76 | 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | - + |
<iconset theme="arrow-down"/>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QListView" name="document_view">
<property name="dragDropMode">
|
| ︙ | |||
115 116 117 118 119 120 121 122 123 124 125 126 127 128 | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | + + + + + + |
</property>
<property name="contextMenuPolicy">
<enum>Qt::ContextMenuPolicy::CustomContextMenu</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDropMode::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::DropAction::MoveAction</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectionBehavior::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
|
| ︙ |
Changes to setup_cx_freeze.py.
| ︙ | |||
20 21 22 23 24 25 26 | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | - + | import pathlib import re import sys from cx_Freeze import setup, Executable ROOT_DIR = pathlib.Path(__file__).parent |
| ︙ | |||
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | + + |
if sys.platform == "win32":
excludes += [
"platformdirs.android",
"platformdirs.macos",
"platformdirs.unix",
]
def get_icon() -> str:
icon_path = resource_path / "icons" / "MTGPP.png"
if sys.platform == "win32":
dest = ROOT_DIR/"MTGPP.ico"
if not dest.exists():
from PIL import Image
with Image.open(icon_path) as src:
src.save(dest, "ICO")
return str(dest)
else:
return str(icon_path)
icon = get_icon()
setup_parameters = {
"executables": [
Executable(
f"{main_package}/__main__.py",
|
| ︙ |
Changes to tests/conftest.py.
| ︙ | |||
56 57 58 59 60 61 62 | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | - + - + - - + + + - + - |
db = mtg_proxy_printer.sqlite_helpers.open_database(":memory:", "document-v7", check_same_thread=False)
if request.param:
db.execute("PRAGMA reverse_unordered_selects = TRUE")
return db
@pytest.fixture
|
Changes to tests/document_controller/test_action_compact_document.py.
| ︙ | |||
20 21 22 23 24 25 26 | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | - + | from mtg_proxy_printer.units_and_sizes import PageType, CardSizes from mtg_proxy_printer.model.document import Document from mtg_proxy_printer.document_controller import IllegalStateError from mtg_proxy_printer.document_controller.card_actions import ActionAddCard from mtg_proxy_printer.document_controller.page_actions import ActionNewPage, ActionRemovePage from mtg_proxy_printer.document_controller.compact_document import ActionCompactDocument |
| ︙ | |||
102 103 104 105 106 107 108 | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | - + |
)
action = ActionCompactDocument()
action.apply(document_light)
assert_that(
action.actions,
contains_exactly(
|
| ︙ | |||
149 150 151 152 153 154 155 | 149 150 151 152 153 154 155 156 157 158 | - + |
card_container_with(oversized1, pages[1]),
card_container_with(oversized2, pages[1])),
)
)
assert_that(
action.actions,
contains_exactly(
|
Changes to tests/document_controller/test_action_edit_document_settings.py.
| ︙ | |||
23 24 25 26 27 28 29 | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | - + | from pytestqt.qtbot import QtBot from mtg_proxy_printer.units_and_sizes import PageType, unit_registry, CardSizes from mtg_proxy_printer.model.page_layout import PageLayoutSettings from mtg_proxy_printer.model.document import Document from mtg_proxy_printer.document_controller.page_actions import ActionNewPage from mtg_proxy_printer.document_controller.card_actions import ActionAddCard |
| ︙ | |||
201 202 203 204 205 206 207 | 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | - + |
action = ActionEditDocumentSettings(document_light.page_layout)
action._already_applied = True
old_settings = action.old_settings = copy.copy(document_light.page_layout)
document_light.page_layout.page_height += 1*unit_registry.mm
action.reflow_actions += [
new_page,
|
| ︙ |
Changes to tests/document_controller/test_action_move_cards.py.
| ︙ | |||
10 11 12 13 14 15 16 | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | - + - + + | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from functools import partial |
| ︙ | |||
60 61 62 63 64 65 66 | 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | - + - + |
def test_apply_raises_exception_when_trying_to_create_a_mixed_size_page(document_light: Document):
ActionNewPage().apply(document_light)
append_new_card_in_page(document_light.pages[0], "Normal", CardSizes.REGULAR)
append_new_card_in_page(document_light.pages[1], "Large", CardSizes.OVERSIZED)
assert_that(document_light.pages[0].page_type(), is_(PageType.REGULAR))
assert_that(document_light.pages[1].page_type(), is_(PageType.OVERSIZED))
|
| ︙ | |||
95 96 97 98 99 100 101 | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | - + |
to_move = append_new_card_in_page(pages[0], "Move")
on_page_1 = append_new_card_in_page(pages[1], "Stay on 1")
row_move_validator = partial(validate_qt_model_move_signal_parameter, 0, 0, 0, 1, 1)
with qtbot.wait_signals(
[document_light.page_type_changed, document_light.rowsAboutToBeMoved, document_light.rowsMoved],
timeout=1000, check_params_cbs=[lambda index: index.row() == 0] +
[row_move_validator] * 2):
|
| ︙ | |||
121 122 123 124 125 126 127 | 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | - + |
on_page_0 = append_new_card_in_page(pages[0], "Stay on 0")
row_move_validator = partial(validate_qt_model_move_signal_parameter, 0, 0, 0, 1, 0)
with qtbot.wait_signals(
[document_light.page_type_changed, document_light.rowsAboutToBeMoved, document_light.rowsMoved],
timeout=1000, check_params_cbs=[lambda index: index.row() == 1] +
[row_move_validator] * 2):
|
| ︙ | |||
146 147 148 149 150 151 152 | 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | - + |
on_page_0 = append_new_card_in_page(pages[0], "Stay on 0")
on_page_1 = append_new_card_in_page(pages[1], "Stay on 1")
row_move_validator = partial(validate_qt_model_move_signal_parameter, 0, 0, 0, 1, 1)
with qtbot.assert_not_emitted(document_light.page_type_changed), \
qtbot.wait_signals(
[document_light.rowsAboutToBeMoved, document_light.rowsMoved],
timeout=1000, check_params_cbs=[row_move_validator] * 2):
|
| ︙ | |||
190 191 192 193 194 195 196 | 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | - + |
"Test setup failed"
)
row_move_validator = partial(validate_qt_model_move_signal_parameter, 0, 1, 2, 1, 2)
with qtbot.assert_not_emitted(document_light.page_type_changed), \
qtbot.wait_signals(
[document_light.rowsAboutToBeMoved, document_light.rowsMoved],
timeout=1000, check_params_cbs=[row_move_validator] * 2):
|
| ︙ | |||
233 234 235 236 237 238 239 | 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | - + - + |
)
row_move_validator_1 = partial(validate_qt_model_move_signal_parameter, 0, 2, 2, 1, 1)
row_move_validator_2 = partial(validate_qt_model_move_signal_parameter, 0, 0, 0, 1, 1)
with qtbot.assert_not_emitted(document_light.page_type_changed), \
qtbot.wait_signals(
[document_light.rowsAboutToBeMoved, document_light.rowsMoved]*2,
timeout=1000, check_params_cbs=[row_move_validator_1] * 2 + [row_move_validator_2] * 2):
|
| ︙ | |||
283 284 285 286 287 288 289 | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | - + |
def test_apply_move_card_with_target_inserts_between_cards(qtbot: QtBot, document_light: Document):
pages = document_light.pages
ActionNewPage().apply(document_light)
card_1 = append_new_card_in_page(pages[0], "Move1")
not_moved = append_new_card_in_page(pages[0], "Stay on 0")
card_2 = append_new_card_in_page(pages[1], "Before")
card_3 = append_new_card_in_page(pages[1], "After")
|
| ︙ | |||
313 314 315 316 317 318 319 | 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | - + |
@pytest.mark.parametrize("target_row", [None, 1]) # Because the target has 1 card, both should give the same result
def test_apply_move_card_with_target_appends_to_page(qtbot: QtBot, document_light: Document, target_row: OptInt):
pages = document_light.pages
ActionNewPage().apply(document_light)
card_1 = append_new_card_in_page(pages[0], "Move1")
not_moved = append_new_card_in_page(pages[0], "Stay on 0")
card_2 = append_new_card_in_page(pages[1], "Before")
|
| ︙ | |||
341 342 343 344 345 346 347 | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | - + - + - - + + |
@pytest.mark.parametrize("target_row", [0, 1, None])
def test_apply_without_indices_does_nothing(qtbot: QtBot, document_light: Document, target_row: OptInt):
pages = document_light.pages
ActionNewPage().apply(document_light)
card_1 = append_new_card_in_page(pages[0], "Move1")
card_2 = append_new_card_in_page(pages[1], "After")
|
| ︙ | |||
600 601 602 603 604 605 606 | 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |
),
contains_exactly(
card_container_with(c3, pages[1]),
)
),
"Incorrect card move"
)
@pytest.fixture()
def document_with_cards(document_light: Document) -> Document:
ActionNewPage(count=3, content=[[], [], []]).apply(document_light)
pages = document_light.pages
content: list[tuple[int, str]] = [
(0, "A1"),
(0, "A2"),
(0, "A3"),
(1, "B1"),
(1, "B2"),
(1, "B3"),
(3, "D1"),
(3, "D2"),
(3, "D3"),
(3, "D4"),
(3, "D5"),
(3, "D6"),
]
for page, name in content:
append_new_card_in_page(pages[page], name)
return document_light
def gather_card_names(document: Document) -> Sequence[str]:
return [
",".join(container.card.name for container in page)
for page in document.pages
]
def generate_test_cases_for_card_moves_between_pages():
# Tuples source, cards_to_move, target_page, target_row, expected
# Origin card order: ["A1,A2,A3", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"]
# Move onto another existing page
yield 0, [0], 1, None, ["A2,A3", "B1,B2,B3,A1", "", "D1,D2,D3,D4,D5,D6"]
yield 0, [0], 1, 3, ["A2,A3", "B1,B2,B3,A1", "", "D1,D2,D3,D4,D5,D6"]
yield 0, [0], 1, 0, ["A2,A3", "A1,B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"]
yield 0, [0, 2], 1, None, ["A2", "B1,B2,B3,A1,A3", "", "D1,D2,D3,D4,D5,D6"]
yield 0, [1], 1, None, ["A1,A3", "B1,B2,B3,A2", "", "D1,D2,D3,D4,D5,D6"]
yield 0, [0, 1, 2], 1, None, ["", "B1,B2,B3,A1,A2,A3", "", "D1,D2,D3,D4,D5,D6"]
yield 0, [0, 1, 2], 1, 1, ["", "B1,A1,A2,A3,B2,B3", "", "D1,D2,D3,D4,D5,D6"]
yield 1, [0], 2, None, ["A1,A2,A3", "B2,B3", "B1", "D1,D2,D3,D4,D5,D6"]
yield 1, [0], 3, None, ["A1,A2,A3", "B2,B3", "", "D1,D2,D3,D4,D5,D6,B1"]
yield 3, [0, 2], 0, None, ["A1,A2,A3,D1,D3", "B1,B2,B3", "", "D2,D4,D5,D6"]
# Move to new page before target_page
yield 3, [0, 2, 3, 5], 0, -1, ["D1,D3,D4,D6", "A1,A2,A3", "B1,B2,B3", "", "D2,D5"]
yield 3, [0, 2, 3, 5], 1, -1, ["A1,A2,A3", "D1,D3,D4,D6", "B1,B2,B3", "", "D2,D5"]
# Move to new page at document end
yield 3, [0, 2, 3, 5], 4, -1, ["A1,A2,A3", "B1,B2,B3", "", "D2,D5", "D1,D3,D4,D6"]
@pytest.mark.parametrize(
"source, cards_to_move, target_page, target_row, expected",
generate_test_cases_for_card_moves_between_pages())
def test_ActionMoveCardsBetweenPages_apply(
document_with_cards: Document,
source: int, cards_to_move: list[int], target_page: int, target_row: int|None,
expected: list[str]):
action = ActionMoveCardsBetweenPages(source, cards_to_move, target_page, target_row)
action.apply(document_with_cards)
result = gather_card_names(document_with_cards)
assert_that(result, contains_exactly(*expected), f"Got: {result}")
@pytest.mark.parametrize(
"source, cards_to_move, target_page, target_row, expected",
generate_test_cases_for_card_moves_between_pages())
def test_ActionMoveCardsBetweenPages_undo(
document_with_cards: Document,
source: int, cards_to_move: list[int], target_page: int, target_row: int|None,
expected: list[str]):
action = ActionMoveCardsBetweenPages(source, cards_to_move, target_page, target_row)
action.apply(document_with_cards)
try:
assert_that(gather_card_names(document_with_cards), contains_exactly(*expected))
except AssertionError:
pytest.skip("Test setup failed")
action.undo(document_with_cards)
result = gather_card_names(document_with_cards)
assert_that(result, contains_exactly("A1,A2,A3", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"), f"Got: {result}")
def generate_test_cases_for_card_moves_within_page():
# Tuples page, cards_to_move, target_row, expected
# Origin card order: ["A1,A2,A3", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"]
yield 0, [0], None, ["A2,A3,A1", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"] # 0
yield 0, [0], 0, ["A1,A2,A3", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"] # 1
yield 0, [0], 1, ["A1,A2,A3", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"] # 2
yield 0, [0], 2, ["A2,A1,A3", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"] # 3
yield 0, [0], 3, ["A2,A3,A1", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"] # 4
yield 3, [0, 1, 5], None, ["A1,A2,A3", "B1,B2,B3", "", "D3,D4,D5,D1,D2,D6"] # 5
yield 3, [0, 5], 0, ["A1,A2,A3", "B1,B2,B3", "", "D1,D6,D2,D3,D4,D5"] # 6
yield 3, [0, 5], 3, ["A1,A2,A3", "B1,B2,B3", "", "D2,D3,D1,D6,D4,D5"] # 7
yield 3, [0, 2], 4, ["A1,A2,A3", "B1,B2,B3", "", "D2,D4,D1,D3,D5,D6"] # 8
yield 3, [3, 5], 0, ["A1,A2,A3", "B1,B2,B3", "", "D4,D6,D1,D2,D3,D5"] # 9
yield 3, [1, 2, 4, 5], 0, ["A1,A2,A3", "B1,B2,B3", "", "D2,D3,D5,D6,D1,D4"] # 10
yield 0, [2], 0, ["A3,A1,A2", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"] # 11
yield 0, [2], 1, ["A1,A3,A2", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"] # 12
yield 0, [2], 2, ["A1,A2,A3", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"] # 13
yield 0, [2], 3, ["A1,A2,A3", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"] # 14
@pytest.mark.parametrize(
"page, cards_to_move, target_row, expected",
generate_test_cases_for_card_moves_within_page())
def test_ActionMoveCardsWithinPage_apply(document_with_cards: Document, page: int, cards_to_move: list[int],
target_row: int|None, expected: list[str]):
ActionMoveCardsWithinPage(page, cards_to_move, target_row).apply(document_with_cards)
result = gather_card_names(document_with_cards)
assert_that(result, contains_exactly(*expected), f"Got: {result}")
@pytest.mark.parametrize(
"page, cards_to_move, target_row, after_apply",
generate_test_cases_for_card_moves_within_page())
def test_ActionMoveCardsWithinPage_undo(document_with_cards: Document, page: int, cards_to_move: list[int],
target_row: int|None, after_apply: list[str]):
(action := ActionMoveCardsWithinPage(page, cards_to_move, target_row)).apply(document_with_cards)
try:
assert_that(gather_card_names(document_with_cards), contains_exactly(*after_apply))
except AssertionError:
pytest.skip("Test setup failed")
action.undo(document_with_cards)
result = gather_card_names(document_with_cards)
assert_that(result, contains_exactly("A1,A2,A3", "B1,B2,B3", "", "D1,D2,D3,D4,D5,D6"), f"Got: {result}")
|