def test_play_turn_loose(self, ch): """Test a turn/game looser""" # Prepare test ch.return_value = i18n.OUT_MSG_COMPLAINTS[0] key = 'a' self.game.hangman.attempt.__bool__.side_effect = [True, False] self.game.ui.accept_letter.return_value = key self.game.word.unmask.return_value = False # Run test self.game.play_turn(key) # Evaluate test calls = [ call.attempt.__bool__(), call.missed.__iadd__(1), call.draw(), call.attempt.__bool__() ] self.game.hangman.assert_has_calls(calls) calls = [ call.accept_letter(key), call.end_turn(i18n.OUT_MSG_COMPLAINTS[0]), call.end_game(i18n.OUT_MSG_LOSER), call.ask_play_again() ] self.game.ui.assert_has_calls(calls) calls = [call.__bool__(), call.unmask(key)] self.game.word.assert_has_calls(calls)
def test__pdf_page_iterator(self): with patch('pdfreader.SimplePDFViewer') as mock: pdf_page_iterator = PDFPageIterator(pdf_viewer=mock) pdf_strings = next(pdf_page_iterator) pdf_strings.get_strings() expected_calls = [call.__bool__(), call.next(), call.render()] self.assertEqual(mock.mock_calls, expected_calls) mock.next.side_effect = PageDoesNotExist with self.assertRaises(StopIteration): next(pdf_page_iterator) self.assertEqual(0, len([page for page in pdf_page_iterator]))
def test___del__(self): mock = MagicMock() tested = BinaryLoggerBis(self.log_file) tested.file_handle.close() # the file handle is correctly closed on instance destruction tested.file_handle = mock del tested expected = [ call.__bool__(), call.close(), ] self.assertEqual(expected, mock.mock_calls)
def test_save(self, fp, mocked_open, mocked_os): # Prepare test self.cache.clean = Mock() self.cache.fp = fp # Execute test self.cache.save() # Evaluate results expected = [call.__bool__(), call.close()] self.assertEqual(expected, fp.mock_calls, ASSERT_MOCK_CALLS) expected = [call(self.cache.cache_file, 'w')] self.assertEqual(expected, mocked_open.mock_calls, ASSERT_MOCK_CALLS) expected = [call.unlink(self.cache.cache_file)] self.assertEqual(expected, mocked_os.mock_calls, ASSERT_MOCK_CALLS) self.cache.clean.assert_called_with(persist=True)
def test_get_repo_caches_honors_batch_size(self, gen_cache: MagicMock) -> None: paths = [f"{idx}_" + p for idx, p in enumerate([self.DUMMY_PATH] * 5)] gen_cache.return_value = {} get_repo_caches( paths, FullRepoMetadataConfig({TypeInferenceProvider}, 1, batch_size=2)) # A call to `gen_cache.__bool__()` will accompany every regular call to gen_cache() due to # the implementation of cache resolving in `libcst.metadata.FullRepoManager`. calls = [ call(Path(""), paths[:2], 1), call(Path(""), paths[2:4], 1), call(Path(""), [paths[4]], 1), ] all_calls = chain.from_iterable([(call.__bool__(), c) for c in calls]) gen_cache.assert_has_calls(all_calls)
def test_should_convert_url_set_to_sources_with_timeextractor(self): number_of_urls = 4 urls_in_set = [self.url + '-{0}'.format(i) for i in range(number_of_urls)] urlset_func = MagicMock(return_value=urls_in_set) urlsrcs_for_set = [MagicMock() for url in urls_in_set] for i in range(number_of_urls): urlsrcs_for_set[i].url = urls_in_set[i] urlsrc_func = MagicMock(side_effect=urlsrcs_for_set) times_for_urls = [self.current_time + url[-1] for url in urls_in_set] timeextractor = MagicMock(side_effect=times_for_urls) converter = source.SourceConverter(urlsrc_func, urlset_func, timeextractor) srcs = converter.to_sources(self.url) calls_expected = [] for urlsrc in urlsrcs_for_set: calls_expected.append(call.__bool__()) calls_expected.append(call(urlsrc.url)) timeextractor.assert_has_calls(calls_expected) self.assertEqual([src.timestamp for src in srcs], times_for_urls)
def test_play_turn_win(self, ch): """Test a turn/game winner""" # Prepare test ch.return_value = i18n.OUT_MSG_CONGRATS[0] key = 'a' self.game.ui.accept_letter.return_value = key self.game.word.unmask.return_value = True self.game.word.is_mask.return_value = False # Run test self.game.play_turn(key) # Evaluate test calls = [call.attempt.__bool__(), call.draw(saved=True)] self.game.hangman.assert_has_calls(calls) calls = [ call.accept_letter(key), call.end_turn(i18n.OUT_MSG_CONGRATS[0]), call.end_game(i18n.OUT_MSG_WINNER), call.ask_play_again() ] self.game.ui.assert_has_calls(calls) calls = [call.__bool__(), call.unmask(key), call.is_mask()] self.game.word.assert_has_calls(calls)
# (at your option) any later version. # # FRED 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 FRED. If not, see <https://www.gnu.org/licenses/>. import os from unittest.mock import call, sentinel from fred_idl.Registry import IsoDateTime from fred_idl.Registry.Whois import KeySet, PlaceAddress, Registrar CALL_BOOL = call.__bool__() TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.contrib.auth.context_processors.auth', 'django.template.context_processors.i18n', 'django.template.context_processors.media', 'django.template.context_processors.static', 'django.template.context_processors.tz', 'django.contrib.messages.context_processors.messages', ], },