Skip to content

Commit

Permalink
added clipboard tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenZcience committed Dec 13, 2024
1 parent db562dd commit 285ce79
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions cat_win/tests/src/service/test_clipboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
class TestClipboard(TestCase):
maxDiff = None

def test_clipabord_clear(self):
Clipboard.clipboard = '42'
Clipboard.clear()
self.assertEqual(Clipboard.clipboard, '')

def test_put_cached(self):
# the patch makes the copy_function not None
with patch.object(Clipboard, 'copy_function') as mocka, patch.object(Clipboard, '_copy') as mockb:
Expand All @@ -39,3 +44,29 @@ def test__copy_importerror(self):
self.assertNotIn('ClipBoardError', fake_out.getvalue())
self.assertIn('ImportError', fake_out.getvalue())
self.assertIn("'--clip'", fake_out.getvalue())

def test_get_cached(self):
# the patch makes the copy_function not None
with patch.object(Clipboard, 'paste_function') as mocka, patch.object(Clipboard, '_paste') as mockb:
Clipboard.get()
mocka.assert_called_once()
mockb.assert_not_called()

def test_get_not_cached(self):
with patch.object(Clipboard, '_paste') as mockb:
self.assertEqual(Clipboard.get(), None)
mockb.assert_called_once()

def test__paste_clipboarderror(self):
with patch('sys.stderr', new=StdOutMock()) as fake_out:
Clipboard._paste(0, True)
self.assertIn('ClipBoardError', fake_out.getvalue())
self.assertNotIn('ImportError', fake_out.getvalue())
self.assertIn("'--clip'", fake_out.getvalue())

def test__paste_importerror(self):
with patch('sys.stderr', new=StdOutMock()) as fake_out:
Clipboard._paste( 0, False)
self.assertNotIn('ClipBoardError', fake_out.getvalue())
self.assertIn('ImportError', fake_out.getvalue())
self.assertIn("'--clip'", fake_out.getvalue())

0 comments on commit 285ce79

Please sign in to comment.