Repo Init.

This commit is contained in:
SL
2024-04-25 09:12:48 +08:00
commit ee5002dbb5
3583 changed files with 348959 additions and 0 deletions
@@ -0,0 +1,28 @@
# ------------------------------------------------------------------
# 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
DIR = os.path.dirname(__file__)
"""
This directory and every sub directory contains tests
"""
def get_test_dirs():
dirs = []
# For every directory and sub directory (including cwd)
for path, _, _ in os.walk(DIR):
# Add the norm'd path to dirs
dirs.append(os.path.normpath(path))
return dirs
@@ -0,0 +1,13 @@
# ------------------------------------------------------------------
# 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 all fixtures from PyInstaller into the tests.
from PyInstaller.utils.conftest import * # noqa: F401,F403
@@ -0,0 +1,3 @@
test_group:
secret_string: secret
secret_number: 123
@@ -0,0 +1,45 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2015-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
# -----------------------------------------------------------------------------
from inspect import getmembers, isfunction
from functools import partial
import boto
import boto.exception
credentials = dict(
aws_access_key_id='ASIAIH3F2FU3T63KIXKA',
aws_secret_access_key='lnN4qk1a0SuQAFVsGA+Y+ujo2/5rLq2j+a1O4Vuy')
# connect_cloudsearchdomain is broken in boto; the rest require custom params
skip = {
'connect_cloudsearchdomain',
'connect_ec2_endpoint',
'connect_gs',
'connect_euca',
'connect_ia',
'connect_walrus',
}
connect_funcs = [
func for name, func in getmembers(boto)
if isfunction(func) and name.startswith('connect_') and name not in skip
]
connect_funcs += [
partial(boto.connect_ec2_endpoint, 'https://ec2.amazonaws.com',
**credentials),
partial(boto.connect_gs, gs_access_key_id='', gs_secret_access_key=''),
partial(boto.connect_euca, host=None, **credentials),
partial(boto.connect_ia, ia_access_key_id='', ia_secret_access_key=''),
partial(boto.connect_walrus, host='s3.amazonaws.com', **credentials),
]
for connect_func in connect_funcs:
if isfunction(connect_func):
connect_func(**credentials)
else:
connect_func()
@@ -0,0 +1,43 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2005-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
# -----------------------------------------------------------------------------
# Enchant hook test. Tested with PyEnchant 1.6.6.
import sys
import enchant
print(80 * '-')
print('PYTHONPATH: %s' % sys.path)
# At least one backend should be available
backends = [x.name for x in enchant.Broker().describe()]
if len(backends) < 1:
raise SystemExit('Error: No dictionary backend available')
print(80 * '-')
print('Backends: ' + ', '.join(backends))
# Usually en_US dictionary should be bundled.
languages = enchant.list_languages()
dicts = [x[0] for x in enchant.list_dicts()]
if len(dicts) < 1:
raise SystemExit('No dictionary available')
print(80 * '-')
print('Languages: %s' % ', '.join(languages))
print('Dictionaries: %s' % dicts)
print(80 * '-')
# Try spell checking if English is availale
language = 'en_US'
if language in languages:
d = enchant.Dict(language)
print('d.check("hallo") %s' % d.check('hallo'))
print('d.check("halllo") %s' % d.check('halllo'))
print('d.suggest("halllo") %s' % d.suggest('halllo'))
@@ -0,0 +1,54 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2014-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
# -----------------------------------------------------------------------------
import os
fnames_to_track = [
'lextab.py',
'yacctab.py',
]
def fnames_found():
return [fname for fname in fnames_to_track if os.path.isfile(fname)]
if __name__ == '__main__':
# Confirm no files exist before we start.
if fnames_found():
raise SystemExit('FAIL: Files present before test.')
# Minimal invocation that generates the files.
from pycparser import c_parser
parser = c_parser.CParser()
# Were the files generated?
fnames_generated = fnames_found()
# Try to remove them, if so.
for fname in fnames_generated:
try:
os.unlink(fname)
except OSError:
pass
# Did we fail at deleting any file?
fnames_left = fnames_found()
# Fail if any file was generated.
if fnames_generated:
if fnames_left:
raise SystemExit('FAIL: Files generated and not removed.')
else:
raise SystemExit('FAIL: Files generated but removed.')
# Success.
@@ -0,0 +1,36 @@
# ------------------------------------------------------------------
# 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
# Force CPU
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
# Display only warnings and errors
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# Begin test - import tensorflow after environment variables are set
import tensorflow as tf # noqa: E402
# Input data: batch of four 28x28x3 images
input_shape = (4, 28, 28, 3)
x = tf.random.normal(input_shape)
# Convolution with 3x3 kernel, two output filters
y = tf.keras.layers.Conv2D(
2,
(3, 3),
activation='relu',
input_shape=input_shape[1:]
)(x)
assert y.shape == (4, 26, 26, 2), "Unexpected output shape!"
@@ -0,0 +1,66 @@
# ------------------------------------------------------------------
# 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 sys
import os
# Force CPU
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
# Display only warnings and errors
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# tensorflow 2.16 and keras 3.0 upgraded the interactive progress bar (displayed during dataset download, during model
# fitting, etc.) with fancier version that uses Unicode arrows (←). For this to work, `sys.stdout` must be using utf-8
# encoding. As per https://docs.python.org/3/library/sys.html#sys.stdout, on Windows, python defaults to using utf-8
# for the console device. However, non-character devices such as pipes use the system locale encoding (i.e. the ANSI
# codepage). PyInstaller's `pyi_builder` test fixture runs the build executable via `subprocess.Popen` with stdout
# and stderr redirected to pipes, so the embedded interpreter in the frozen test application ends up using system
# locale encoding (e.g., cp1252) instead of utf-8 for `sys.stdout` and `sys.stderr`. In contrast to unfrozen python,
# the encoding cannot be overridden by the calling process via `PYTHONIOENCODING` environment variable when starting
# the application (sub)process. However, we can reconfigure the encoding on the stream objects here, in the application
# itself. Which, everything considered, is the sanest place to do so.
if sys.stdout.encoding != 'utf8':
sys.stdout.reconfigure(encoding='utf-8')
if sys.stderr.encoding != 'utf8':
sys.stderr.reconfigure(encoding='utf-8')
# Begin test - import tensorflow after environment variables are set
import tensorflow as tf # noqa: E402
# Load and normalize the dataset
mnist = tf.keras.datasets.mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
# Define model...
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(10)
])
# ... and loss function
loss_fn = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Train
model.compile(optimizer='adam', loss=loss_fn, metrics=['accuracy'])
model.fit(x_train, y_train, epochs=1, verbose=1)
# Evaluate
results = model.evaluate(x_test, y_test, verbose=1)
# Expected accuracy after a single epoch is around 95%, so use 90%
# as a passing bar
assert results[1] >= 0.90, "Resulting accuracy on validation set too low!"
@@ -0,0 +1,361 @@
# ------------------------------------------------------------------
# Copyright (c) 2023 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 pytest
from PyInstaller.utils.tests import importorskip
# Run the tests in onedir mode only
onedir_only = pytest.mark.parametrize('pyi_builder', ['onedir'], indirect=True)
# Basic transformers test with BERT-based unmasker
@importorskip('transformers')
@importorskip('torch')
@onedir_only
def test_transformers_bert_pipeline(pyi_builder):
pyi_builder.test_source("""
import transformers
unmasker = transformers.pipeline('fill-mask', model='bert-base-uncased')
output = unmasker("Hello I'm a [MASK] model.")
print("Unmasked text:", output)
""")
# Trying to import DebertaModel triggers error about missing source files for TorchScript
@importorskip('transformers')
@importorskip('torch')
@onedir_only
def test_transformers_deberta_import(pyi_builder):
pyi_builder.test_source("""
from transformers import DebertaConfig, DebertaModel
configuration = DebertaConfig()
model = DebertaModel(configuration)
""")
# Building models from tabular data example from https://docs.fast.ai/quick_start.html
@importorskip('fastai')
@onedir_only
def test_fastai_tabular_data(pyi_builder):
pyi_builder.test_source("""
from fastai.tabular.all import *
path = untar_data(URLs.ADULT_SAMPLE)
print(f"Dataset path: {path}")
dls = TabularDataLoaders.from_csv(
path/'adult.csv',
path=path,
y_names="salary",
cat_names = [
'workclass',
'education',
'marital-status',
'occupation',
'relationship',
'race',
],
cont_names = [
'age',
'fnlwgt',
'education-num',
],
procs = [
Categorify,
FillMissing,
Normalize,
],
)
learn = tabular_learner(dls, metrics=accuracy)
learn.fit_one_cycle(2)
learn.show_results()
""")
@importorskip('timm')
@onedir_only
def test_timm_model_creation(pyi_builder):
pyi_builder.test_source("""
import timm
# List available models
pretrained_models = timm.list_models(pretrained=True)
print(f"Pre-trained models: {len(pretrained_models)}")
assert len(pretrained_models) > 0
# Create a model (non-trained version, to avoid downloading weights)
model = timm.create_model("resnet50d", pretrained=False)
print(model)
""")
@importorskip('lightning')
@importorskip('torchvision')
@importorskip('torch')
@onedir_only
def test_lightning_mnist_autoencoder(pyi_builder):
pyi_builder.test_source("""
import os
# On macOS, multiprocessing seems to be used at some point...
if __name__ == '__main__':
import multiprocessing
multiprocessing.freeze_support()
import torch
import torchvision
import lightning
class LitAutoEncoder(lightning.LightningModule):
def __init__(self):
super().__init__()
self.encoder = torch.nn.Sequential(
torch.nn.Linear(28 * 28, 128),
torch.nn.ReLU(),
torch.nn.Linear(128, 3),
)
self.decoder = torch.nn.Sequential(
torch.nn.Linear(3, 128),
torch.nn.ReLU(),
torch.nn.Linear(128, 28 * 28),
)
def forward(self, x):
embedding = self.encoder(x)
return embedding
def training_step(self, batch, batch_idx):
x, y = batch
x = x.view(x.size(0), -1)
z = self.encoder(x)
x_hat = self.decoder(z)
loss = torch.nn.functional.mse_loss(x_hat, x)
return loss
def configure_optimizers(self):
optimizer = torch.optim.Adam(
self.parameters(),
lr=1e-3,
)
return optimizer
# Dataset
dataset = torchvision.datasets.MNIST(
os.path.dirname(__file__),
download=True,
transform=torchvision.transforms.ToTensor(),
)
dataset_size = len(dataset)
num_samples = 100
train, val = torch.utils.data.random_split(
dataset,
[num_samples, dataset_size - num_samples],
)
# Train
autoencoder = LitAutoEncoder()
trainer = lightning.Trainer(max_epochs=1, logger=False)
trainer.fit(
autoencoder,
torch.utils.data.DataLoader(train),
)
""")
@importorskip('bitsandbytes')
@onedir_only
def test_bitsandbytes(pyi_builder):
pyi_builder.test_source("""
import bitsandbytes
# Instantiate a model and optimizer
dim1 = 256
dim2 = 256
linear = bitsandbytes.nn.Linear8bitLt(dim1, dim2, bias=True, has_fp16_weights=False, threshold=6.0)
adam = bitsandbytes.optim.Adam8bit(linear.parameters(), lr=0.001, betas=(0.9, 0.995))
""")
@importorskip('linear_operator')
@onedir_only
def test_linear_operator(pyi_builder):
pyi_builder.test_source("""
import torch
from linear_operator.operators import DiagLinearOperator, LowRankRootLinearOperator
diag1 = 0.1 + torch.rand(100)
diag2 = 0.1 + torch.rand(100)
mat1 = DiagLinearOperator(diag1)
mat2 = DiagLinearOperator(diag2)
result = (mat1 + mat2).diagonal()
""")
# Based on https://docs.gpytorch.ai/en/latest/examples/01_Exact_GPs/Simple_GP_Regression.html
@importorskip('gpytorch')
@onedir_only
def test_gpytorch_simple_gp_regression(pyi_builder):
pyi_builder.test_source("""
import math
import torch
import gpytorch
## Training
# Training data is 100 points in [0,1] inclusive regularly spaced
train_x = torch.linspace(0, 1, 100)
# True function is sin(2*pi*x) with Gaussian noise
train_y = torch.sin(train_x * (2 * math.pi)) + torch.randn(train_x.size()) * math.sqrt(0.04)
# We will use the simplest form of GP model, exact inference
class ExactGPModel(gpytorch.models.ExactGP):
def __init__(self, train_x, train_y, likelihood):
super().__init__(train_x, train_y, likelihood)
self.mean_module = gpytorch.means.ConstantMean()
self.covar_module = gpytorch.kernels.ScaleKernel(gpytorch.kernels.RBFKernel())
def forward(self, x):
mean_x = self.mean_module(x)
covar_x = self.covar_module(x)
return gpytorch.distributions.MultivariateNormal(mean_x, covar_x)
# Initialize likelihood and model
likelihood = gpytorch.likelihoods.GaussianLikelihood()
model = ExactGPModel(train_x, train_y, likelihood)
# Find optimal model hyperparameters
training_iter = 2
model.train()
likelihood.train()
# Use the adam optimizer
optimizer = torch.optim.Adam(model.parameters(), lr=0.1) # Includes GaussianLikelihood parameters
# "Loss" for GPs - the marginal log likelihood
mll = gpytorch.mlls.ExactMarginalLogLikelihood(likelihood, model)
print("Training the model...")
for i in range(training_iter):
# Zero gradients from previous iteration
optimizer.zero_grad()
# Output from model
output = model(train_x)
# Calc loss and backprop gradients
loss = -mll(output, train_y)
loss.backward()
print('Iter %d/%d - Loss: %.3f lengthscale: %.3f noise: %.3f' % (
i + 1, training_iter, loss.item(),
model.covar_module.base_kernel.lengthscale.item(),
model.likelihood.noise.item()
))
optimizer.step()
## Inference
# Get into evaluation (predictive posterior) mode
model.eval()
likelihood.eval()
# Test points are regularly spaced along [0,1]
# Make predictions by feeding model through likelihood
with torch.no_grad(), gpytorch.settings.fast_pred_var():
test_x = torch.linspace(0, 1, 51)
observed_pred = likelihood(model(test_x))
print("Test X:", test_x.numpy())
print("Predicted Y:", observed_pred.mean.numpy())
""")
# Basic import test for fvcore.nn, which shows that we need to collect its source .py files for TorchScript/JIT.
@importorskip('fvcore')
@onedir_only
def test_fvcore(pyi_builder):
pyi_builder.test_source("""
import fvcore.nn
""")
# Basic test for detectron2, which shows that we need to collect its source .py files for TorchScript/JIT.
@importorskip('detectron2')
@onedir_only
def test_detectron2(pyi_builder):
pyi_builder.test_source("""
from detectron2 import model_zoo
from detectron2.config import get_cfg
from detectron2.engine import DefaultTrainer
cfg = get_cfg()
print("Config:", cfg)
# We cannot instantiate DefaultTrainer without specifying training datasets in config...
#trainer = DefaultTrainer(cfg)
#print(trainer)
""")
# Hugging Face datasets: Download squad dataset (76 MB train, 10 MB validation)
@importorskip('datasets')
@onedir_only
def test_datasets_download_squad(pyi_builder):
pyi_builder.test_source("""
from datasets import load_dataset
from huggingface_hub import list_datasets
# Print all the available datasets
available_datasets = [dataset.id for dataset in list_datasets()]
print("Available datasets:", len(available_datasets))
# Load a dataset and print the first example in the training set
print("Loading squad dataset...")
squad_dataset = load_dataset('squad')
print("First sample:", squad_dataset['train'][0])
""")
# Basic test for Hugging Face accelerate framework
@importorskip('accelerate')
@onedir_only
def test_accelerate(pyi_builder):
pyi_builder.test_source("""
import torch
from accelerate import Accelerator
accelerator = Accelerator()
device = accelerator.device
print("Accelerator device:", device)
model = torch.nn.Transformer().to(device)
optimizer = torch.optim.Adam(model.parameters())
model, optimizer = accelerator.prepare(model, optimizer)
print("Model:", model)
print("Optimizer:", optimizer)
""")
# Basic import test for fairscale, which shows that we need to collect its source .py files for TorchScript/JIT.
@importorskip('fairscale')
@onedir_only
def test_fairscale(pyi_builder):
pyi_builder.test_source("""
import fairscale
""")
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,191 @@
# ------------------------------------------------------------------
# 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 pytest
from PyInstaller.utils.tests import importorskip
# Run the tests in onedir mode only
torch_onedir_only = pytest.mark.parametrize('pyi_builder', ['onedir'], indirect=True)
@importorskip('torch')
@torch_onedir_only
def test_torch(pyi_builder):
pyi_builder.test_source("""
import torch
torch.rand((10, 10)) * torch.rand((10, 10))
""")
# Test with torchaudio transform that uses torchcript, which requires
# access to transforms' sources.
@importorskip('torchaudio')
@torch_onedir_only
def test_torchaudio_scripted_transforms(pyi_builder):
pyi_builder.test_source("""
import numpy as np
import torch.nn
import torchaudio.transforms
# Generate a sine waveform
volume = 0.5 # range [0.0, 1.0]
sampling_rate = 44100 # sampling rate, Hz
duration = 5.0 # seconds
freq = 500.0 # sine frequency, Hz
points = np.arange(0, sampling_rate * duration)
signal = volume * np.sin(2 * np.pi * points * freq / sampling_rate)
# Resample the signal using scripted transform
transforms = torch.nn.Sequential(
torchaudio.transforms.Resample(
orig_freq=sampling_rate,
new_freq=sampling_rate // 2
),
)
scripted_transforms = torch.jit.script(transforms)
signal_tensor = torch.from_numpy(signal).float()
resampled_tensor = scripted_transforms(signal_tensor)
print("Result size:", resampled_tensor.size())
assert len(resampled_tensor) == len(signal_tensor) / 2
""")
# Test with torchtext transform that uses torchcript, which requires
# access to transforms' sources.
@importorskip('torchtext')
@torch_onedir_only
def test_torchtext_scripted_berta_tokenizer_transform(pyi_builder):
pyi_builder.test_source("""
import torch.nn
import torchtext.models
import torchtext.functional
# Create Roberta Encoder with Base configuration
roberta_base = torchtext.models.ROBERTA_BASE_ENCODER
classifier_head = torchtext.models.RobertaClassificationHead(num_classes=2, input_dim=768)
transform = roberta_base.transform()
# Create transform that uses torchscript
scripted_transform = torch.jit.script(transform)
print(scripted_transform)
# Prepare test data
small_input_batch = [
"Hello world",
"How are you!",
]
model_input = torchtext.functional.to_tensor(scripted_transform(small_input_batch), padding_value=1)
print("Tokenized input:", model_input)
# Process
if False:
# Downloads the model (~ 240 MB), if necessary.
model = roberta_base.get_model(head=classifier_head)
output = model(model_input)
print(output)
print(output.shape)
""")
@importorskip('torchvision')
@torch_onedir_only
def test_torchvision_nms(pyi_builder):
pyi_builder.test_source("""
import torch
import torchvision
# boxes: Nx4 tensor (x1, y1, x2, y2)
boxes = torch.tensor([
[0.0, 0.0, 1.0, 1.0],
[0.45, 0.0, 1.0, 1.0],
])
# scores: Nx1 tensor
scores = torch.tensor([
1.0,
1.1
])
keep = torchvision.ops.nms(boxes, scores, 0.5)
# The boxes have IoU of 0.55, and the second one has a slightly
# higher score, so we expect it to be kept while the first one
# is discarded.
assert keep == 1
""")
# Ensure that torchvision.io.image manages to load torchvision.image extension for its ops.
@importorskip('torchvision')
@torch_onedir_only
def test_torchvision_image_io(pyi_builder):
pyi_builder.test_source("""
import torch
import torchvision.io.image
image = torch.zeros((3, 100, 100), dtype=torch.uint8)
png_data = torchvision.io.image.encode_png(image)
decoded_image = torchvision.io.image.decode_png(png_data)
assert torch.equal(image, decoded_image), "Original and decoded image are not identical!"
""")
# Advanced tests that uses torchvision.datasets and torchvision.transforms;
# the transforms are combined using torchscript, which requires access to
# transforms' sources.
@importorskip('torchvision')
@torch_onedir_only
def test_torchvision_scripted_transforms(pyi_builder):
pyi_builder.test_source("""
import torch
import torch.nn
import torchvision.transforms
import torchvision.datasets
# Generate one image, and convert it from PIL to tensor
preproc = torchvision.transforms.Compose([
torchvision.transforms.PILToTensor()
])
dataset = torchvision.datasets.FakeData(
size=1, # 1 image
image_size=(3, 200, 200),
num_classes=2,
transform=preproc,
)
assert len(dataset) == 1
image, category = dataset[0]
assert image.size() == (3, 200, 200)
assert image.dtype == torch.uint8
# Create a composite transform that uses torchscript
transforms = torch.nn.Sequential(
torchvision.transforms.RandomCrop(100),
torchvision.transforms.RandomHorizontalFlip(p=0.3),
)
scripted_transforms = torch.jit.script(transforms)
# Transform image
transformed_image = scripted_transforms(image)
assert transformed_image.size() == (3, 100, 100)
assert transformed_image.dtype == torch.uint8
""")
@@ -0,0 +1,70 @@
# ------------------------------------------------------------------
# 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 pytest
from PyInstaller.utils.hooks import is_module_satisfies
from PyInstaller.utils.tests import importorskip
# Run the tests in onedir mode only
onedir_only = pytest.mark.parametrize('pyi_builder', ['onedir'], indirect=True)
# Basic import tests for sub-packages of skimage. Run only on demand, and only in onedir mode.
@pytest.mark.slow
@onedir_only
@importorskip('skimage')
@pytest.mark.skipif(
not is_module_satisfies('scikit_image >= 0.16'),
reason='The test supports only scikit-image >= 0.16.',
)
@pytest.mark.parametrize('submodule', [
'color', 'data', 'draw', 'exposure', 'feature', 'filters', 'future',
'graph', 'io', 'measure', 'metrics', 'morphology', 'registration',
'restoration', 'segmentation', 'transform', 'util'
])
def test_skimage(pyi_builder, submodule):
pyi_builder.test_source("""
import skimage.{0}
""".format(submodule))
# Test the ORB descriptor, which requires the data file with descriptor sample points.
@importorskip('skimage')
def test_skimage_feature_orb(pyi_builder):
pyi_builder.test_source("""
import skimage.feature
import numpy as np
# Prepare test images
img1 = np.zeros((100, 100))
img2 = np.zeros_like(img1)
rng = np.random.default_rng(1984)
square = rng.random((20, 20))
img1[40:60, 40:60] = square
img2[53:73, 53:73] = square
# ORB detector/descriptor extractor
detector_extractor1 = skimage.feature.ORB(n_keypoints=5)
detector_extractor2 = skimage.feature.ORB(n_keypoints=5)
# Process
detector_extractor1.detect_and_extract(img1)
detector_extractor2.detect_and_extract(img2)
matches = skimage.feature.match_descriptors(
detector_extractor1.descriptors,
detector_extractor2.descriptors,
)
print(matches)
""")
@@ -0,0 +1,46 @@
# ------------------------------------------------------------------
# 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 pytest
from PyInstaller.utils.hooks import is_module_satisfies
from PyInstaller.utils.tests import importorskip
# Run the tests in onedir mode only
onedir_only = pytest.mark.parametrize('pyi_builder', ['onedir'], indirect=True)
# Basic import tests for sub-packages of sklearn. Run only on demand, and only in onedir mode.
@pytest.mark.slow
@onedir_only
@importorskip('sklearn')
@pytest.mark.skipif(
not is_module_satisfies('scikit_learn >= 0.21'),
reason='The test supports only scikit-learn >= 0.21.',
)
@pytest.mark.parametrize('submodule', [
'calibration', 'cluster', 'covariance', 'cross_decomposition',
'datasets', 'decomposition', 'dummy', 'ensemble', 'exceptions',
'experimental', 'externals', 'feature_extraction',
'feature_selection', 'gaussian_process', 'inspection',
'isotonic', 'kernel_approximation', 'kernel_ridge',
'linear_model', 'manifold', 'metrics', 'mixture',
'model_selection', 'multiclass', 'multioutput',
'naive_bayes', 'neighbors', 'neural_network', 'pipeline',
'preprocessing', 'random_projection', 'semi_supervised',
'svm', 'tree', 'discriminant_analysis', 'impute', 'compose'
])
def test_sklearn(pyi_builder, submodule):
pyi_builder.test_source("""
import sklearn.{0}
""".format(submodule))
@@ -0,0 +1,55 @@
# ------------------------------------------------------------------
# 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 pytest
from PyInstaller.utils.tests import importorskip
# Run the tests in onedir mode only
tensorflow_onedir_only = pytest.mark.parametrize('pyi_builder', ['onedir'], indirect=True)
@importorskip('tensorflow')
@tensorflow_onedir_only
def test_tensorflow(pyi_builder):
pyi_builder.test_source(
"""
from tensorflow import *
"""
)
# Test if tensorflow.keras imports properly result in tensorflow being collected.
# See https://github.com/pyinstaller/pyinstaller/discussions/6890
@importorskip('tensorflow')
@tensorflow_onedir_only
def test_tensorflow_keras_import(pyi_builder):
pyi_builder.test_source(
"""
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, LSTM, Dropout
from tensorflow.keras.optimizers import Adam
"""
)
@importorskip('tensorflow')
@tensorflow_onedir_only
def test_tensorflow_layer(pyi_builder):
pyi_builder.test_script('pyi_lib_tensorflow_layer.py')
@importorskip('tensorflow')
@tensorflow_onedir_only
def test_tensorflow_mnist(pyi_builder):
pyi_builder.test_script('pyi_lib_tensorflow_mnist.py')
@@ -0,0 +1,64 @@
#-----------------------------------------------------------------------------
# Copyright (c) 2005-2023, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------
from PyInstaller.utils.tests import importorskip
@importorskip('wx.lib.pubsub')
def test_wx_lib_pubsub_protocol_default(pyi_builder):
pyi_builder.test_source(
"""
from wx.lib.pubsub import pub
def on_message(number):
print('Message received.')
if not number == 762:
raise SystemExit('Message data "762" expected but received "%s".' % str(number))
pub.subscribe(on_message, 'topic.subtopic')
pub.sendMessage('topic.subtopic', number=762)
""")
# Functional test exercising the non-default protocol `arg1` of version 3 of the PyPubSub API.
@importorskip('wx.lib.pubsub.core')
def test_wx_lib_pubsub_protocol_kwargs(pyi_builder):
pyi_builder.test_source(
"""
from wx.lib.pubsub import setuparg1 # noqa: F401
from wx.lib.pubsub import pub
def on_message(message):
print('Message received.')
if not message.data == 762:
raise SystemExit('Message data "762" expected but received "%s".' % str(message.data))
pub.subscribe(on_message, 'topic.subtopic')
pub.sendMessage('topic.subtopic', 762)
""")
# Functional test exercising the default protocol `kwargs` of version 3 of the PyPubSub API.
@importorskip('wx.lib.pubsub.core')
def test_wx_lib_pubsub_protocol_arg1(pyi_builder):
pyi_builder.test_source(
"""
from wx.lib.pubsub import setupkwargs # noqa: F401
from wx.lib.pubsub import pub
def on_message(number):
print('Message received.')
if not number == 762:
raise SystemExit('Message data "762" expected but received "%s".' % str(number))
pub.subscribe(on_message, 'topic.subtopic')
pub.sendMessage('topic.subtopic', number=762)
""")