def test_cached(self, mock_export, mock_display, mock_generate, mock_makedirs, mock_process_input_source): mock_process_input_source.side_effect = lambda input_source, api_key: input_source environ = {} argv = [] stdout = io.StringIO() input_source = '' cols = 160 rows = 40 cell_width = 3 cell_height = 6 num_frames = 11 seconds = 1.1 with patch('gif_for_cli.execute.open') as mocked_open: mocked_open.return_value = io.StringIO( json.dumps({ 'input_source': input_source, 'input_source_file': input_source, 'cols': cols, 'rows': rows, 'cell_width': cell_width, 'cell_height': cell_height, 'num_frames': num_frames, 'seconds': seconds, })) with patch('gif_for_cli.execute.os.path.exists') as mock_exists: mock_exists.return_value = True execute(environ, argv, stdout) self.assertEqual(mock_process_input_source.call_count, 1) # for some reaosn, this intercepts some locale laoding paths = sorted( [call[0][0] for call in mock_exists.call_args_list[-6:]]) self.assertTrue(paths[0].endswith( '/d41d8cd98f00b204e9800998ecf8427e-160cols-40rows-cw3px-ch6px')) self.assertEqual(mock_makedirs.call_count, 0) self.assertEqual(mock_generate.call_count, 0) self.assertEqual(mocked_open.call_count, 1) self.assertEqual(mock_display.call_count, 1) self.assertEqual(mock_display.call_args[1]['seconds_per_frame'], 0.1) self.assertEqual(mock_export.call_count, 0)
def playGif(url): cols = os.get_terminal_size().columns rows = os.get_terminal_size().lines execute( os.environ, [ "--display-mode", "256", "--rows", f"{rows}", "--cols", f"{cols}", "-l", "20", url, ], sys.stdout, )
def gif(): random_gif = random.choice(os.listdir('./gifs/')) execute.execute(os.environ, [f'./gifs/{random_gif}'], sys.stdout)
import os import sys from gif_for_cli.execute import execute while True: execute(os.environ, ["test.gif"], sys.stdout)