i fixed some test codes.

This commit is contained in:
Shinya Koyano 2025-02-17 01:03:54 +09:00
parent 91df24ca4f
commit 03bdb98fc4
Signed by: moli
GPG key ID: 61EDE6AC103CC456

View file

@ -18,16 +18,6 @@ import pillow_avif
import argparse
from magika import Magika
if 'ANVIL_API_PORT' not in os.environ:
print('not in Anvil.')
sys.exit(1)
host = 'localhost'
ANVIL_API_PORT = os.environ['ANVIL_API_PORT']
ANVIL_API_SESS = os.environ['ANVIL_API_SESS']
ANVIL_WIN_ID = os.environ['ANVIL_WIN_ID']
def getSuffix(byts):
'''
get the filetype in the byts, and change sufifix
@ -56,8 +46,8 @@ def download(url):
download the iamge file to the temporary file.
>>> import aecpic
>>> n, t = aecpic.download('https://moli-green.xyz/img.webp')
>>> assert n != None and t == 'webp'
>>> r = aecpic.download('https://moli-green.xyz/img.webp')
>>> assert r != ''
'''
cr = subprocess.run(['curl', url], capture_output = True)
@ -79,11 +69,11 @@ def getPNG(url):
'''
Download the file from the URL, convert and save to PNG format.
>>> import apcpic
>>> r = apcpic.getPNG('https://moli-green.xyz/img.webp')
>>> if r != '':
... pass
>>> import aecpic
>>> r = aecpic.getPNG('https://moli-green.xyz/img.webp')
>>> assert r != ''
'''
png_filename = ''
with tempfile.NamedTemporaryFile(
mode='wb',
@ -96,12 +86,14 @@ def getPNG(url):
img.save(png_filename)
return png_filename
def get_anvil_window():
def get_anvil_window(host='localhost'):
'''
Get or create Anvil's window.
'''
global ANVIL_WIN_ID
ANVIL_API_PORT = os.environ['ANVIL_API_PORT']
ANVIL_API_SESS = os.environ['ANVIL_API_SESS']
ANVIL_WIN_ID = os.environ['ANVIL_WIN_ID']
if ANVIL_WIN_ID != '':
return ANVIL_WIN_ID
@ -131,7 +123,9 @@ def anvil_Pic(host='localhost', url=None):
filename = getPNG(url)
anvil_win_id = get_anvil_window()
ANVIL_API_PORT = os.environ['ANVIL_API_PORT']
ANVIL_API_SESS = os.environ['ANVIL_API_SESS']
ANVIL_WIN_ID = get_anvil_window()
h = {
'Anvil-Sess': ANVIL_API_SESS,
@ -158,5 +152,10 @@ if __name__ == '__main__':
p.add_argument('url', help='Image URL')
arg = p.parse_args()
host = arg.host
if 'ANVIL_API_PORT' not in os.environ:
print('not in Anvil.')
sys.exit(1)
anvil_Pic(host, arg.url)