def test_select_none(self, mock_setvalue): "User chooses to have no cookie cutter" cookie_cutter_choice().load(TESTDATA / '2x2.inselect_cookie_cutter') self.assertEqual( '2x2 (4 boxes)', cookie_cutter_choice().current.name ) self.window.cookie_cutter_widget.clear() self.assertEqual(None, cookie_cutter_choice().current) mock_setvalue.assert_called_with(cookie_cutter_choice().PATH_KEY, '')
def test_cancels_choose_cookie_cutter(self, mock_gofn): "User cancels the 'choose cookie cutter' box" w = self.window w.cookie_cutter_widget.clear() w.cookie_cutter_widget.choose() self.assertEqual(None, cookie_cutter_choice().current) self.assertEqual(1, mock_gofn.call_count)
def test_chooses_cookie_cutter(self, mock_setvalue): "User chooses cookie cutter" w = self.window w.cookie_cutter_widget.clear() path = TESTDATA / '2x2.inselect_cookie_cutter' retval = str(path), w.cookie_cutter_widget.FILE_FILTER with patch.object(QFileDialog, 'getOpenFileName', return_value=retval) as mock_gofn: w.cookie_cutter_widget.choose() self.assertEqual(1, mock_gofn.call_count) self.assertEqual( '2x2 (4 boxes)', cookie_cutter_choice().current.name ) mock_setvalue.assert_any_call(cookie_cutter_choice().PATH_KEY, str(path)) mock_setvalue.assert_any_call( cookie_cutter_choice().DIRECTORY_KEY, str(path.parent) )
def test_save_to_cookie_cutter(self, mock_setvalue): "Create a new cookie cutter" w = self.window w.open_document(TESTDATA / 'test_segment.inselect') with temp_directory_with_files() as tempdir: path = tempdir / 'My new cookie cutter{0}'.format( CookieCutter.EXTENSION ) retval = str(path), w.cookie_cutter_widget.FILE_FILTER with patch.object(QFileDialog, 'getSaveFileName', return_value=retval): w.save_to_cookie_cutter() cookie_cutter = CookieCutter.load(path) # The new cookie cutter should have been created with 5 boxes self.assertEqual(5, len(cookie_cutter.document_items)) self.assertEqual( 'My new cookie cutter (5 boxes)', cookie_cutter_choice().current.name )
def test_save_to_cookie_cutter(self, mock_setvalue): "Create a new cookie cutter" w = self.window w.open_document(path=TESTDATA / 'shapes.inselect') with temp_directory_with_files() as tempdir: path = tempdir / 'My new cookie cutter{0}'.format( CookieCutter.EXTENSION ) retval = str(path), w.cookie_cutter_widget.FILE_FILTER with patch.object(QFileDialog, 'getSaveFileName', return_value=retval): w.save_to_cookie_cutter() cookie_cutter = CookieCutter.load(path) # The new cookie cutter should have been created with 5 boxes self.assertEqual(5, len(cookie_cutter.document_items)) self.assertEqual( 'My new cookie cutter (5 boxes)', cookie_cutter_choice().current.name )