|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +# |
| 4 | +# A library that provides a Python interface to the Telegram Bot API |
| 5 | +# Copyright (C) 2015-2018 |
| 6 | +# Leandro Toledo de Souza <[email protected]> |
| 7 | +# |
| 8 | +# This program is free software: you can redistribute it and/or modify |
| 9 | +# it under the terms of the GNU Lesser Public License as published by |
| 10 | +# the Free Software Foundation, either version 3 of the License, or |
| 11 | +# (at your option) any later version. |
| 12 | +# |
| 13 | +# This program is distributed in the hope that it will be useful, |
| 14 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +# GNU Lesser Public License for more details. |
| 17 | +# |
| 18 | +# You should have received a copy of the GNU Lesser Public License |
| 19 | +# along with this program. If not, see [http://www.gnu.org/licenses/]. |
| 20 | +import os |
| 21 | +import subprocess |
| 22 | +import sys |
| 23 | + |
| 24 | +from telegram import InputFile |
| 25 | + |
| 26 | + |
| 27 | +class TestInputFile(object): |
| 28 | + png = os.path.join('tests', 'data', 'game.png') |
| 29 | + |
| 30 | + def test_subprocess_pipe(self): |
| 31 | + if sys.platform == 'win32': |
| 32 | + cmd = ['type', self.png] |
| 33 | + else: |
| 34 | + cmd = ['cat', self.png] |
| 35 | + |
| 36 | + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=(sys.platform == 'win32')) |
| 37 | + in_file = InputFile({'photo': proc.stdout}) |
| 38 | + |
| 39 | + assert in_file.input_file_content == open(self.png, 'rb').read() |
| 40 | + assert in_file.mimetype == 'image/png' |
| 41 | + assert in_file.filename == 'image.png' |
| 42 | + |
| 43 | + proc.kill() |
0 commit comments