forked from pyinstaller/pyinstaller-hooks-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_libraries.py
2120 lines (1613 loc) · 54.7 KB
/
test_libraries.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ------------------------------------------------------------------
# Copyright (c) 2020 PyInstaller Development Team.
#
# This file is distributed under the terms of the GNU General Public
# License (version 2.0 or later).
#
# The full license is available in LICENSE.GPL.txt, distributed with
# this software.
#
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------
import os
from pathlib import Path
import pytest
from PyInstaller.compat import is_darwin, is_linux, is_py39, is_win
from PyInstaller.utils.hooks import is_module_satisfies, can_import_module, get_module_attribute
from PyInstaller.utils.tests import importorskip, requires, xfail
@importorskip('fiona')
def test_fiona(pyi_builder):
pyi_builder.test_source(
'''
import fiona
'''
)
@importorskip('fiona')
def test_fiona_transform(pyi_builder):
# Test that fiona in frozen application has access to its projections database. If projection data is unavailable,
# the transform becomes an identity transform.
pyi_builder.test_source(
"""
from fiona.transform import transform_geom
from fiona.crs import from_epsg
eiffel_tower = {
'type': 'Point',
'coordinates': (2.294694, 48.858093),
}
crs_source = from_epsg(4326) # WGS84
crs_target = from_epsg(25831) # ETRS89 / UTM zone 31N
transformed = transform_geom(crs_source, crs_target, eiffel_tower)
print(f"Transformed point: {transformed}")
# Expected coordinates: obtained by manually running this program unfrozen
EXPECTED_COORDINATES = (448265.9146792292, 5411920.651338793)
EPS = 1e-6
delta = [abs(value - expected) for value, expected in zip(transformed["coordinates"], EXPECTED_COORDINATES)]
print(f"Delta: {delta}")
assert all([value < EPS for value in delta]), f"Delta {delta} exceeds threshold!"
"""
)
@importorskip('jinxed')
def test_jinxed(pyi_builder):
pyi_builder.test_source(
'''
import jinxed
jinxed.setupterm('xterm')
assert jinxed._terminal.TERM.terminfo is jinxed.terminfo.xterm
'''
)
@importorskip("geopandas")
def test_geopandas(pyi_builder):
pyi_builder.test_source(
'''
import geopandas
'''
)
@importorskip('trimesh')
def test_trimesh(pyi_builder):
pyi_builder.test_source(
"""
import trimesh
"""
)
@importorskip('apscheduler')
def test_apscheduler(pyi_builder):
pyi_builder.test_source(
"""
import apscheduler
import pytz
import asyncio
import random
import datetime as dt
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.triggers.interval import IntervalTrigger
loop = asyncio.get_event_loop()
async def test_function(data=0):
print(dt.datetime.now(), random.randint(0, 100))
test_scheduler = AsyncIOScheduler()
test_scheduler.add_job(
test_function,
id="TestJob",
trigger=IntervalTrigger(
seconds=1,
start_date=dt.datetime.now(tz=pytz.UTC)
)
)
test_scheduler.start()
loop.run_until_complete(asyncio.sleep(5))
"""
)
@importorskip('boto')
@xfail(reason='boto does not fully support Python 3')
def test_boto(pyi_builder):
pyi_builder.test_script('pyi_lib_boto.py')
@xfail(reason='Issue #1844.')
@importorskip('boto3')
def test_boto3(pyi_builder):
pyi_builder.test_source(
"""
import boto3
session = boto3.Session(region_name='us-west-2')
# verify all clients
for service in session.get_available_services():
session.client(service)
# verify all resources
for resource in session.get_available_resources():
session.resource(resource)
""")
@xfail(reason='Issue #1844.')
@importorskip('botocore')
def test_botocore(pyi_builder):
pyi_builder.test_source(
"""
import botocore
from botocore.session import Session
session = Session()
# verify all services
for service in session.get_available_services():
session.create_client(service, region_name='us-west-2')
""")
@xfail(is_darwin, reason='Issue #1895.')
@importorskip('enchant')
def test_enchant(pyi_builder):
pyi_builder.test_script('pyi_lib_enchant.py')
@importorskip('zmq')
def test_zmq(pyi_builder):
pyi_builder.test_source(
"""
import zmq
print(zmq.__version__)
print(zmq.zmq_version())
# This is a problematic module and might cause some issues.
import zmq.utils.strtypes
""")
@importorskip('pylint')
def test_pylint(pyi_builder):
pyi_builder.test_source(
"""
# The following more obvious test doesn't work::
#
# import pylint
# pylint.run_pylint()
#
# because pylint will exit with 32, since a valid command
# line wasn't given. Instead, provide a valid command line below.
from pylint.lint import Run
Run(['-h'])
""")
@importorskip('markdown')
def test_markdown(pyi_builder):
# Markdown uses __import__ed extensions. Make sure these work by
# trying to use the 'toc' extension, using both short and long format.
pyi_builder.test_source(
"""
import markdown
print(markdown.markdown('testing',
extensions=['toc']))
print(markdown.markdown('testing',
extensions=['markdown.extensions.toc']))
""")
@importorskip('pylsl')
def test_pylsl(pyi_builder):
pyi_builder.test_source(
"""
import pylsl
print(pylsl.version.__version__)
""")
@importorskip('lxml')
def test_lxml_isoschematron(pyi_builder):
pyi_builder.test_source(
"""
# The import of this module triggers the loading of some
# required XML files.
from lxml import isoschematron
""")
@importorskip('openpyxl')
def test_openpyxl(pyi_builder):
pyi_builder.test_source(
"""
# Test the hook to openpyxl
from openpyxl import __version__
""")
@importorskip('pyodbc')
def test_pyodbc(pyi_builder):
pyi_builder.test_source(
"""
# pyodbc is a binary Python module. On Windows when installed with easy_install
# it is installed as zipped Python egg. This binary module is extracted
# to PYTHON_EGG_CACHE directory. PyInstaller should find the binary there and
# include it with frozen executable.
import pyodbc
""")
@importorskip('pyttsx')
def test_pyttsx(pyi_builder):
pyi_builder.test_source(
"""
# Basic code example from pyttsx tutorial.
# http://packages.python.org/pyttsx/engine.html#examples
import pyttsx
engine = pyttsx.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
""")
@importorskip('pyttsx3')
def test_pyttsx3(pyi_builder):
pyi_builder.test_source("""
import pyttsx3
engine = pyttsx3.init()
""")
@importorskip('pycparser')
def test_pycparser(pyi_builder):
pyi_builder.test_script('pyi_lib_pycparser.py')
@importorskip('Crypto')
def test_pycrypto(pyi_builder):
pyi_builder.test_source(
"""
import binascii
from Crypto.Cipher import AES
BLOCK_SIZE = 16
print('AES null encryption, block size', BLOCK_SIZE)
# Just for testing functionality after all
print('HEX', binascii.hexlify(
AES.new(b"\\0" * BLOCK_SIZE, AES.MODE_ECB).encrypt(b"\\0" * BLOCK_SIZE)))
from Crypto.PublicKey import ECC
""")
@importorskip('Cryptodome')
def test_cryptodome(pyi_builder):
pyi_builder.test_source(
"""
from Cryptodome import Cipher
from Cryptodome.PublicKey import ECC
print('Cryptodome Cipher Module:', Cipher)
""")
@importorskip('h5py')
def test_h5py(pyi_builder):
pyi_builder.test_source("""
import h5py
""")
@importorskip('unidecode')
def test_unidecode(pyi_builder):
pyi_builder.test_source("""
from unidecode import unidecode
# Unidecode should not skip non-ASCII chars if mappings for them exist.
assert unidecode(u"kožušček") == "kozuscek"
""")
@importorskip('pinyin')
def test_pinyin(pyi_builder):
pyi_builder.test_source("""
import pinyin
""")
@importorskip('uvloop')
@pytest.mark.darwin
@pytest.mark.linux
def test_uvloop(pyi_builder):
pyi_builder.test_source("import uvloop")
@importorskip('web3')
def test_web3(pyi_builder):
pyi_builder.test_source("import web3")
@importorskip('phonenumbers')
def test_phonenumbers(pyi_builder):
pyi_builder.test_source("""
import phonenumbers
number = '+17034820623'
parsed_number = phonenumbers.parse(number)
assert(parsed_number.country_code == 1)
assert(parsed_number.national_number == 7034820623)
""")
@importorskip('pendulum')
def test_pendulum(pyi_builder):
pyi_builder.test_source("""
import pendulum
print(pendulum.now().isoformat())
""")
@importorskip('humanize')
def test_humanize(pyi_builder):
pyi_builder.test_source("""
import humanize
from datetime import timedelta
print(humanize.naturaldelta(timedelta(seconds=125)))
""")
@importorskip('argon2')
def test_argon2(pyi_builder):
pyi_builder.test_source("""
from argon2 import PasswordHasher
ph = PasswordHasher()
hash = ph.hash("s3kr3tp4ssw0rd")
ph.verify(hash, "s3kr3tp4ssw0rd")
""")
@importorskip('pytest')
def test_pytest_runner(pyi_builder):
"""
Check if pytest runner builds correctly.
"""
pyi_builder.test_source(
"""
import pytest
import sys
sys.exit(pytest.main(['--help']))
""")
@importorskip('eel')
def test_eel(pyi_builder):
pyi_builder.test_source("import eel")
@importorskip('sentry_sdk')
def test_sentry(pyi_builder):
pyi_builder.test_source(
"""
import sentry_sdk
sentry_sdk.init()
""")
@importorskip('iminuit')
def test_iminuit(pyi_builder):
pyi_builder.test_source("""
from iminuit import Minuit
""")
@importorskip('av')
def test_av(pyi_builder):
pyi_builder.test_source("""
import av
""")
@importorskip('passlib')
@xfail(is_linux and is_py39 and not is_module_satisfies('passlib > 1.7.4'),
reason='Passlib does not account for crypt() behavior change that '
'was introduced in 3.9.x (python #39289).')
def test_passlib(pyi_builder):
pyi_builder.test_source("""
import passlib.apache
""")
@importorskip('publicsuffix2')
def test_publicsuffix2(pyi_builder):
pyi_builder.test_source("""
import publicsuffix2
publicsuffix2.PublicSuffixList()
""")
@importorskip('pydivert')
def test_pydivert(pyi_builder):
pyi_builder.test_source("""
import pydivert
pydivert.WinDivert.check_filter("inbound")
""")
@importorskip('statsmodels')
@pytest.mark.skipif(not is_module_satisfies('statsmodels >= 0.12'),
reason='This has only been tested with statsmodels >= 0.12.')
def test_statsmodels(pyi_builder):
pyi_builder.test_source("""
import statsmodels.api as sm
""")
@importorskip('win32ctypes')
@pytest.mark.skipif(not is_win, reason='pywin32-ctypes is supported only on Windows')
@pytest.mark.parametrize('submodule', ['win32api', 'win32cred', 'pywintypes'])
def test_pywin32ctypes(pyi_builder, submodule):
pyi_builder.test_source("""
from win32ctypes.pywin32 import {0}
""".format(submodule))
@importorskip('pyproj')
@pytest.mark.skipif(not is_module_satisfies('pyproj >= 2.1.3'),
reason='The test supports only pyproj >= 2.1.3.')
def test_pyproj(pyi_builder):
pyi_builder.test_source("""
import pyproj
tf = pyproj.Transformer.from_crs(
7789,
8401
)
result = tf.transform(
xx=3496737.2679,
yy=743254.4507,
zz=5264462.9620,
tt=2019.0
)
print(result)
""")
@importorskip('pydantic')
def test_pydantic(pyi_builder):
pyi_builder.test_source("""
import datetime
import pprint
import pydantic
class User(pydantic.BaseModel):
id: int
name: str = 'John Doe'
signup_ts: datetime.datetime
external_data = {'id': 'not an int', }
try:
User(**external_data)
except pydantic.ValidationError as e:
pprint.pprint(e.errors())
""")
@requires('google-api-python-client >= 2.0.0')
def test_googleapiclient(pyi_builder):
pyi_builder.test_source("""
from googleapiclient import discovery, discovery_cache
API_NAME = "youtube"
API_VERSION = "v3"
for file in os.listdir(discovery_cache.DISCOVERY_DOC_DIR): # Always up to date
if file.startswith("youtube.v") and file.endswith(".json"):
API_NAME, API_VERSION = file.split(".")[:2]
break
# developerKey can be any non-empty string
yt = discovery.build(API_NAME, API_VERSION, developerKey=":)", static_discovery=True)
""")
@importorskip('eth_typing')
def test_eth_typing(pyi_builder):
pyi_builder.test_source("""
import eth_typing
""")
@importorskip("eth_utils")
def test_eth_utils_network(pyi_builder):
pyi_builder.test_source("""
import eth_utils.network
eth_utils.network.name_from_chain_id(1)
""")
@importorskip('plotly')
@importorskip('pandas')
def test_plotly(pyi_builder):
pyi_builder.test_source("""
import pandas as pd
import plotly.express as px
data = [(1, 1), (2, 1), (3, 5), (4, -3)]
df = pd.DataFrame.from_records(data, columns=['col_1', 'col_2'])
fig = px.scatter(df, x='col_1', y='col_2')
""")
@pytest.mark.timeout(600)
@importorskip('dash')
def test_dash(pyi_builder):
pyi_builder.test_source("""
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.Input(id='input_text', type='text', placeholder='input type text'),
html.Div(id='out-all-types'),
]
)
@app.callback(
Output('out-all-types', 'children'),
[Input('input_text', 'value')],
)
def cb_render(val):
return val
""")
@importorskip('dash_table')
def test_dash_table(pyi_builder):
pyi_builder.test_source("""
import dash
import dash_table
app = dash.Dash(__name__)
app.layout = dash_table.DataTable(
id='table',
columns=[{'name': 'a', 'id': 'a'}, {'name': 'b', 'id': 'b'}],
data=[{'a': 1, 'b': 2}, {'a': 3, 'b': 4}],
)
""")
@importorskip('dash_bootstrap_components')
def test_dash_bootstrap_components(pyi_builder):
pyi_builder.test_source("""
import dash
import dash_bootstrap_components as dbc
import dash_html_components as html
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
alert = dbc.Alert([html.H4('Well done!', className='alert-heading')])
""")
@importorskip('blspy')
def test_blspy(pyi_builder):
pyi_builder.test_source("""
import blspy
""")
@importorskip('flirpy')
def test_flirpy(pyi_builder):
pyi_builder.test_source("""
from flirpy.camera.lepton import Lepton
print(Lepton.find_video_device())
""")
@importorskip('office365')
def test_office365(pyi_builder):
pyi_builder.test_source("""
from office365.runtime.auth.providers.saml_token_provider import SamlTokenProvider
SamlTokenProvider._prepare_request_from_template('FederatedSAML.xml', {})
SamlTokenProvider._prepare_request_from_template('RST2.xml', {})
SamlTokenProvider._prepare_request_from_template('SAML.xml', {})
""")
@importorskip('thinc')
def test_thinc(pyi_builder):
pyi_builder.test_source("""
from thinc.backends import numpy_ops
""")
@importorskip('srsly')
def test_srsly(pyi_builder):
pyi_builder.test_source("""
import srsly
""")
@importorskip('spacy')
def test_spacy(pyi_builder):
pyi_builder.test_source("""
import spacy
""")
@importorskip('shotgun_api3')
def test_shotgun_api3(pyi_builder):
pyi_builder.test_source("""
import shotgun_api3
""")
@importorskip('msoffcrypto')
def test_msoffcrypto(pyi_builder):
pyi_builder.test_source("""
import msoffcrypto
""")
@importorskip('mariadb')
def test_mariadb(pyi_builder):
pyi_builder.test_source("""
import mariadb
""")
@importorskip('dash_uploader')
def test_dash_uploader(pyi_builder):
pyi_builder.test_source("""
import dash_uploader
""")
@importorskip('cloudscraper')
def test_cloudscraper(pyi_builder):
pyi_builder.test_source("""
import cloudscraper
scraper = cloudscraper.create_scraper()
""")
@importorskip('mnemonic')
def test_mnemonic(pyi_builder):
pyi_builder.test_source("""
import mnemonic
mnemonic.Mnemonic("english")
""")
@importorskip('pynput')
def test_pynput(pyi_builder):
pyi_builder.test_source("""
import pynput
""")
@importorskip('pystray')
def test_pystray(pyi_builder):
pyi_builder.test_source("""
import pystray
""")
@importorskip('rtree')
def test_rtree(pyi_builder):
pyi_builder.test_source("""
import rtree
""")
@importorskip('pingouin')
def test_pingouin(pyi_builder):
pyi_builder.test_source("""
import pingouin
""")
@importorskip('timezonefinder')
def test_timezonefinder(pyi_builder):
pyi_builder.test_source("""
from timezonefinder import TimezoneFinder
TimezoneFinder()
""")
@importorskip('uvicorn')
def test_uvicorn(pyi_builder):
pyi_builder.test_source("""
from uvicorn import lifespan, loops
""")
@importorskip("langdetect")
def test_langdetect(pyi_builder):
pyi_builder.test_source("""
import langdetect
print(langdetect.detect("this is a test"))
""")
@importorskip("swagger_spec_validator")
def test_swagger_spec_validator(pyi_builder):
pyi_builder.test_source("""
from swagger_spec_validator.common import read_resource_file
read_resource_file("schemas/v1.2/resourceListing.json")
read_resource_file("schemas/v2.0/schema.json")
""")
@requires('pythonnet < 3.dev')
@pytest.mark.skipif(not is_win, reason='pythonnet 2 does not support .Net Core, so its only supported by Windows')
def test_pythonnet2(pyi_builder):
pyi_builder.test_source("""
import clr
""")
@requires('pythonnet >= 3.dev')
def test_pythonnet3(pyi_builder):
pyi_builder.test_source("""
from clr_loader import get_coreclr
from pythonnet import set_runtime
set_runtime(get_coreclr()) # Pick up and use any installed .NET runtime.
import clr
""")
if is_win:
# This is a hack to prevent monkeypatch from interfering with PyQt5's additional PATH entries. See:
# https://github.com/pyinstaller/pyinstaller/commit/b66c9021129e9e875ddd138a298ce542483dd6c9
try:
import PyQt5 # noqa: F401
except ImportError:
pass
@importorskip("qtmodern")
@importorskip("PyQt5")
def test_qtmodern(pyi_builder):
pyi_builder.test_source("""
import sys
from PyQt5 import QtWidgets
import qtmodern.styles
import qtmodern.windows
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
qtmodern.styles.dark(app)
modern_window = qtmodern.windows.ModernWindow(window)
modern_window.show()
""")
@importorskip("platformdirs")
def test_platformdirs(pyi_builder):
pyi_builder.test_source("""
import platformdirs
platformdirs.user_data_dir("FooApp", "Mr Foo")
""")
@importorskip("websockets")
def test_websockets(pyi_builder):
pyi_builder.test_source("import websockets")
@importorskip("tableauhyperapi")
def test_tableauhyperapi(pyi_builder):
pyi_builder.test_source("""
import tableauhyperapi
""")
@importorskip("pymssql")
def test_pymssql(pyi_builder):
pyi_builder.test_source("""
import pymssql
""")
@importorskip("branca")
def test_branca(pyi_builder):
pyi_builder.test_source("""
import branca
""")
@importorskip("folium")
def test_folium(pyi_builder):
pyi_builder.test_source("""
import folium
m = folium.Map(location=[0, 0], zoom_start=5)
""")
@importorskip("metpy")
def test_metpy(pyi_builder):
# Import metpy.plots, which triggers search for colortables data.
pyi_builder.test_source("""
import metpy.plots
""")
@importorskip("pyvjoy")
def test_pyvjoy(pyi_builder):
pyi_builder.test_source("""
import pyvjoy
""")
@importorskip("adbutils")
def test_adbutils(pyi_builder):
# adbutils 0.15.0 renamed adbutils._utils.get_adb_exe() to adb_path()
if is_module_satisfies("adbutils >= 0.15.0"):
pyi_builder.test_source("""
from adbutils._utils import adb_path; adb_path()
""")
else:
pyi_builder.test_source("""
from adbutils._utils import get_adb_exe; get_adb_exe()
""")
@importorskip("pymediainfo")
def test_pymediainfo(pyi_builder):
pyi_builder.test_source("""
from pymediainfo import MediaInfo
MediaInfo._get_library() # Trigger search for shared library.
""")
@importorskip("sacremoses")
def test_sacremoses(pyi_builder):
pyi_builder.test_source("""
import sacremoses
""")
@importorskip("pypeteer")
def test_pypeteer(pyi_builder):
pyi_builder.test_source("""
import pypeteer
print(pypeteer.version)
""")
@importorskip("tzdata")
@pytest.mark.skipif(not is_py39 and not can_import_module('importlib_resources'),
reason='importlib_resources is required on python < 3.9.')
def test_tzdata(pyi_builder):
pyi_builder.test_source("""
import tzdata.zoneinfo # hiddenimport
try:
import importlib.resources as importlib_resources
except ImportError:
import importlib_resources
# This emulates time-zone data retrieval from tzdata, as peformed by
# zoneinfo / backports.zoneinfo
zone_name = "Europe/Ljubljana"
components = zone_name.split("/")
package_name = ".".join(["tzdata.zoneinfo"] + components[:-1])
resource_name = components[-1]
with importlib_resources.open_binary(package_name, resource_name) as fp:
data = fp.read()
print(data)
""")
@importorskip("backports.zoneinfo")
@pytest.mark.skipif(is_win and not can_import_module('tzdata'),
reason='On Windows, backports.zoneinfo requires tzdata.')
def test_backports_zoneinfo(pyi_builder):
pyi_builder.test_source("""
from backports import zoneinfo
tz = zoneinfo.ZoneInfo("Europe/Ljubljana")
print(tz)
""")
@importorskip("zoneinfo")
@pytest.mark.skipif(is_win and not can_import_module('tzdata'),
reason='On Windows, zoneinfo requires tzdata.')
def test_zoneinfo(pyi_builder):
pyi_builder.test_source("""
import zoneinfo
tz = zoneinfo.ZoneInfo("Europe/Ljubljana")
print(tz)
""")
@importorskip("panel")
def test_panel(pyi_builder):
pyi_builder.test_source("""
import panel
# Load the Ace extension to trigger lazy-loading of model
panel.extension("ace")
""")
@importorskip("pyviz_comms")
def test_pyviz_comms(pyi_builder):
pyi_builder.test_source("""
import pyviz_comms
""")
@importorskip("pyphen")
def test_pyphen(pyi_builder):
pyi_builder.test_source("""
import pyphen
""")
@importorskip("pandas")
@importorskip("plotly")
@importorskip("kaleido")
def test_kaleido(pyi_builder):
pyi_builder.test_source("""
import plotly.express as px
fig = px.scatter(px.data.iris(), x="sepal_length", y="sepal_width", color="species")
fig.write_image("figure.png", engine="kaleido")
""")
@pytest.mark.skipif(is_win,
reason='On Windows, Cairo dependencies cannot be installed using Chocolatey.')
@importorskip("cairocffi")
def test_cairocffi(pyi_builder):
pyi_builder.test_source("""
import cairocffi
""")
@pytest.mark.skipif(is_win,
reason='On Windows, Cairo dependencies cannot be installed using Chocolatey.')
@importorskip("cairosvg")
def test_cairosvg(pyi_builder):
pyi_builder.test_source("""
import cairosvg
""")
@importorskip("ffpyplayer")
def test_ffpyplayer(pyi_builder):
pyi_builder.test_source("""