def load_words(self, words_path): with open(words_path) as f: choice = 0 if choice == 0: self.word_shuffler = WordShuffler(f) else: self.word_shuffler = WordStripper(f)
def test_set_item_mixed_case(): word_shuffler = WordShuffler() word1 = 'bag' word_shuffler['a'] = word1 word2 = word_shuffler['A'] assert word2 == word1
def test_make_clue_missing_word(): word_shuffler = WordShuffler(min_words=2) target_letter = 'b' word_shuffler[target_letter] = 'blue' expected_clue = 'B' clue = word_shuffler.make_clue(target_letter) assert clue == expected_clue
def test_display_empty(): word_shuffler = WordShuffler() target_letter = 'e' expected_display = 'E word needed.' display = word_shuffler.make_display(target_letter) assert display == expected_display
def test_make_clue_missing_letter(): word_shuffler = WordShuffler() target_letter = 'w' word_shuffler[target_letter] = 'rapid' expected_clue = 'W' clue = word_shuffler.make_clue(target_letter) assert clue == expected_clue
def test_setitem(): word_shuffler = WordShuffler() word1 = 'bag' letter = 'a' word_shuffler[letter] = word1 word2 = word_shuffler[letter] assert word2 == word1
def test_make_clue_must_match(): word_shuffler = WordShuffler() target_letter = 'a' word_shuffler[target_letter] = 'aa' only_clue = '(_)_\nAA' clue = word_shuffler.make_clue(target_letter) assert clue == only_clue
def test_display_mixed_case(): all_words = 'THE big bag of words'.split() word_shuffler = WordShuffler(all_words) word_shuffler['E'] = 'tHe' expected_display = 'thE' display = word_shuffler.make_display('e') assert display == expected_display
def test_display_single(): all_words = 'the big bag of words'.split() word_shuffler = WordShuffler(all_words) target_letter = 'e' word_shuffler[target_letter] = 'the' expected_display = 'thE' display = word_shuffler.make_display(target_letter) assert display == expected_display
def test_display(): all_words = 'lots of words rail the liar from his lair with lira'.split() word_shuffler = WordShuffler(all_words) target_letter = 'a' word_shuffler[target_letter] = 'liar' expected_display = 'liAr - raIl, laIr, liRa' display = word_shuffler.make_display(target_letter) assert display == expected_display
def test_display_unknown_words(): all_words = 'THE gob bag of words'.split() word_shuffler = WordShuffler(all_words) target_letter = 'o' word_shuffler[target_letter] = 'bog' expected_display = 'bOg (unknown word) - gOb' display = word_shuffler.make_display(target_letter) assert display == expected_display
def test_display_repeated_letter_chosen(): all_words = 'respect the sceptre of a spectre'.split() word_shuffler = WordShuffler(all_words) target_letter = 'e' word_shuffler[target_letter] = 'respEct' expected_display = 'respEct - scepTre, specTre' display = word_shuffler.make_display(target_letter) assert display == expected_display
def test_make_clues(monkeypatch): monkeypatch.setattr(sliced_art.word_shuffler, 'shuffle', mock_shuffle) word_shuffler = WordShuffler([]) word_shuffler['a'] = 'black' word_shuffler['o'] = 'book' expected_clues = dict(a='_ _(_)_ _\nKCALB', o='_(_)_ _\nKOOB') clues = word_shuffler.make_clues() assert clues == expected_clues
def test_display_with_space(): all_words = 'towards a roasted dinner'.split() word_shuffler = WordShuffler(all_words) target_letter = 'w' word_shuffler[target_letter] = 'to wards' expected_display = 'toWards' display = word_shuffler.make_display(target_letter) assert display == expected_display
def test_display_missing_letter(): all_words = 'towards a roasted dinner'.split() word_shuffler = WordShuffler(all_words) target_letter = 'w' word_shuffler[target_letter] = 'roasted' expected_display = 'W word needed.' display = word_shuffler.make_display(target_letter) assert display == expected_display
def test_make_clue_never_matches(): word_shuffler = WordShuffler() target_letter = 'o' word_shuffler[target_letter] = 'mom' forbidden_clue = '_(_)_\nMOM' for _ in range(100): clue = word_shuffler.make_clue(target_letter) assert clue != forbidden_clue
def test_make_clue(monkeypatch): monkeypatch.setattr(sliced_art.word_shuffler, 'shuffle', mock_shuffle) word_shuffler = WordShuffler() target_letter = 'w' word_shuffler[target_letter] = 'towards' expected_clue = '_ _(_)_ _ _ _\nSDRAWOT' clue = word_shuffler.make_clue(target_letter) assert clue == expected_clue
def test_find_other_words_new_lines(): all_words = StringIO('''\ the gab bag of words ''') word_shuffler = WordShuffler(all_words) target_letter = 'G' word_shuffler[target_letter] = 'Bag' expected_display = 'baG - gaB' display = word_shuffler.make_display(target_letter) assert display == expected_display
def __init__(self): super(MainWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.art_scene = QGraphicsScene(self) self.art_scene.addText('Open an image file.') self.ui.art_view.setScene(self.art_scene) self.symbols_scene = QGraphicsScene(self) self.ui.symbols_view.setScene(self.symbols_scene) self.ui.action_exit.triggered.connect(self.close) self.ui.action_open_art.triggered.connect(self.open_image) self.ui.action_open_words.triggered.connect(self.open_words) self.ui.action_save.triggered.connect(self.save_pdf) self.ui.action_save_png.triggered.connect(self.save_png) self.ui.action_shuffle.triggered.connect(self.shuffle) self.ui.action_sort.triggered.connect(self.sort) self.ui.rows.valueChanged.connect(self.on_options_changed) self.ui.columns.valueChanged.connect(self.on_options_changed) self.ui.word_clues_radio.toggled.connect(self.on_options_changed) self.ui.symbol_clues_radio.toggled.connect(self.on_options_changed) self.word_layout = QGridLayout(self.ui.word_content) self.ui.word_scroll.setWidgetResizable(True) self.word_labels: typing.Dict[str, QLabel] = {} self.word_shuffler = WordShuffler([]) self.clues = None self.pixmap = self.scaled_pixmap = self.mini_pixmap = None self.sliced_pixmap_item: typing.Optional[QGraphicsPixmapItem] = None self.sliced_image: typing.Optional[QImage] = None self.selection_grid: typing.Optional[SelectionGrid] = None self.cells = [] self.art_shuffler: typing.Optional[ArtShuffler] = None self.symbols_source_pixmap_item: typing.Optional[ QGraphicsPixmapItem] = None self.symbols_pixmap_item: typing.Optional[QGraphicsPixmapItem] = None self.symbols_image: typing.Optional[QImage] = None self.symbols_shuffler: typing.Optional[ArtShuffler] = None self.selected_row: typing.Optional[int] = None self.selected_column: typing.Optional[int] = None self.settings = QSettings() self.image_path: typing.Optional[str] = self.settings.value( 'image_path') self.words_path: typing.Optional[str] = self.settings.value( 'words_path') self.dirty_letters = set() self.timer = QTimer() self.timer.setInterval(500) self.timer.setSingleShot(True) # noinspection PyUnresolvedReferences self.timer.timeout.connect(self.on_dirty) self.row_count = self.column_count = 0 self.clue_type = ClueType.words self.ui.rows.setValue(self.settings.value('row_count', 6, int)) self.ui.columns.setValue(self.settings.value('column_count', 4, int)) clue_type_name = self.settings.value('clue_type', ClueType.words.name) try: clue_type = ClueType[clue_type_name] except KeyError: clue_type = ClueType.words if clue_type == ClueType.words: self.ui.word_clues_radio.setChecked(True) else: self.ui.symbol_clues_radio.setChecked(True) self.row_clues: typing.List[QPixmap] = [] self.column_clues: typing.List[QPixmap] = [] self.on_options_changed()