|
| 1 | +from PartSeg._roi_analysis.profile_export import ExportDialog, ImportDialog, ProfileDictViewer |
| 2 | + |
| 3 | + |
| 4 | +class TestImportDialog: |
| 5 | + def test_create(self, qtbot, lower_threshold_profile, border_rim_profile): |
| 6 | + dialog = ImportDialog( |
| 7 | + {lower_threshold_profile.name: lower_threshold_profile, border_rim_profile.name: border_rim_profile}, |
| 8 | + {lower_threshold_profile.name: lower_threshold_profile}, |
| 9 | + viewer=ProfileDictViewer, |
| 10 | + ) |
| 11 | + qtbot.addWidget(dialog) |
| 12 | + |
| 13 | + def test_check(self, qtbot, lower_threshold_profile, border_rim_profile): |
| 14 | + dialog = ImportDialog( |
| 15 | + {lower_threshold_profile.name: lower_threshold_profile, border_rim_profile.name: border_rim_profile}, |
| 16 | + {lower_threshold_profile.name: lower_threshold_profile}, |
| 17 | + viewer=ProfileDictViewer, |
| 18 | + ) |
| 19 | + qtbot.addWidget(dialog) |
| 20 | + assert set(dialog.get_import_list()) == { |
| 21 | + (border_rim_profile.name, border_rim_profile.name), |
| 22 | + (lower_threshold_profile.name, lower_threshold_profile.name), |
| 23 | + } |
| 24 | + dialog.uncheck_all() |
| 25 | + assert not dialog.get_import_list() |
| 26 | + dialog.check_all() |
| 27 | + assert set(dialog.get_import_list()) == { |
| 28 | + (border_rim_profile.name, border_rim_profile.name), |
| 29 | + (lower_threshold_profile.name, lower_threshold_profile.name), |
| 30 | + } |
| 31 | + |
| 32 | + def test_preview(self, qtbot, lower_threshold_profile, border_rim_profile): |
| 33 | + dialog = ImportDialog( |
| 34 | + {lower_threshold_profile.name: lower_threshold_profile, border_rim_profile.name: border_rim_profile}, |
| 35 | + {lower_threshold_profile.name: lower_threshold_profile}, |
| 36 | + viewer=ProfileDictViewer, |
| 37 | + ) |
| 38 | + qtbot.addWidget(dialog) |
| 39 | + assert dialog.viewer.toPlainText() == "" |
| 40 | + dialog.list_view.setCurrentItem(dialog.list_view.topLevelItem(0)) |
| 41 | + assert dialog.viewer.toPlainText() != "" |
| 42 | + dialog.list_view.setCurrentItem(dialog.list_view.topLevelItem(1)) |
| 43 | + assert dialog.viewer.toPlainText() != "" |
| 44 | + |
| 45 | + def test_rename(self, qtbot, lower_threshold_profile, border_rim_profile): |
| 46 | + dialog = ImportDialog( |
| 47 | + {lower_threshold_profile.name: lower_threshold_profile, border_rim_profile.name: border_rim_profile}, |
| 48 | + {lower_threshold_profile.name: lower_threshold_profile, border_rim_profile.name: border_rim_profile}, |
| 49 | + viewer=ProfileDictViewer, |
| 50 | + ) |
| 51 | + qtbot.addWidget(dialog) |
| 52 | + item = dialog.list_view.topLevelItem(0) |
| 53 | + assert dialog.list_view.itemWidget(item, 1).isChecked() |
| 54 | + dialog.list_view.itemWidget(item, 2).setChecked(True) |
| 55 | + assert not dialog.list_view.itemWidget(item, 1).isChecked() |
| 56 | + |
| 57 | + |
| 58 | +class TestExportDialog: |
| 59 | + def test_create(self, qtbot, lower_threshold_profile): |
| 60 | + dialog = ExportDialog( |
| 61 | + export_dict={lower_threshold_profile.name: lower_threshold_profile}, viewer=ProfileDictViewer |
| 62 | + ) |
| 63 | + qtbot.addWidget(dialog) |
| 64 | + |
| 65 | + def test_check(self, qtbot, lower_threshold_profile, border_rim_profile): |
| 66 | + dialog = ExportDialog( |
| 67 | + export_dict={ |
| 68 | + lower_threshold_profile.name: lower_threshold_profile, |
| 69 | + border_rim_profile.name: border_rim_profile, |
| 70 | + }, |
| 71 | + viewer=ProfileDictViewer, |
| 72 | + ) |
| 73 | + qtbot.addWidget(dialog) |
| 74 | + assert set(dialog.get_checked()) == {lower_threshold_profile.name, border_rim_profile.name} |
| 75 | + dialog.uncheck_all() |
| 76 | + assert not dialog.get_checked() |
| 77 | + dialog.check_all() |
| 78 | + assert set(dialog.get_checked()) == {lower_threshold_profile.name, border_rim_profile.name} |
| 79 | + |
| 80 | + def test_preview(self, qtbot, lower_threshold_profile, border_rim_profile): |
| 81 | + dialog = ExportDialog( |
| 82 | + export_dict={ |
| 83 | + lower_threshold_profile.name: lower_threshold_profile, |
| 84 | + border_rim_profile.name: border_rim_profile, |
| 85 | + }, |
| 86 | + viewer=ProfileDictViewer, |
| 87 | + ) |
| 88 | + qtbot.addWidget(dialog) |
| 89 | + assert dialog.viewer.toPlainText() == "" |
| 90 | + dialog.list_view.setCurrentRow(0) |
| 91 | + assert dialog.viewer.toPlainText() != "" |
0 commit comments