repo_id stringclasses 409
values | prefix large_stringlengths 34 36.3k | target large_stringlengths 1 498 | assertion_type stringclasses 31
values | difficulty stringclasses 8
values | test_file stringlengths 10 121 | test_function stringlengths 1 104 | test_class stringlengths 0 51 | lineno int32 2 11.3k | commit_idx int32 |
|---|---|---|---|---|---|---|---|---|---|
lightly-ai/lightly | import unittest
import torch
import torch.nn as nn
import torchvision
import lightly
from lightly.models import MoCo, ResNetGenerator
def get_backbone(resnet, num_ftrs=64):
last_conv_channels = list(resnet.children())[-1].in_features
backbone = nn.Sequential(
lightly.models.batchnorm.get_norm_layer(3... | model) | self.assertIsNotNone | variable | tests/models/test_ModelsMoCo.py | test_create_variations_cpu | TestModelsMoCo | 32 | null |
lightly-ai/lightly | import os
import shutil
import tempfile
import unittest
from typing import List, Tuple
import numpy as np
import torchvision
from PIL.Image import Image
from lightly.data import LightlyDataset
from lightly.data._utils import check_images
from lightly.transforms.torchvision_v2_compatibility import torchvision_transfor... | n_healthy | assert | variable | tests/data/test_LightlyDataset.py | test_check_images | TestLightlyDataset | 158 | null |
lightly-ai/lightly | from typing import List, Optional
import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient
from lightly.api.api_workflow_tags import TagDoesNotExistError
from lightly.openapi_generated.swagger_client.models import TagCreator, TagData
from tests.api_workflow import utils
def _get_... | "0x4" | assert | string_literal | tests/api_workflow/test_api_workflow_tags.py | test_create_tag_from_filenames | 49 | null | |
lightly-ai/lightly | import unittest
import torch
import torch.nn as nn
import torchvision
import lightly
from lightly.models import ResNetGenerator, SimCLR
def get_backbone(resnet, num_ftrs=64):
last_conv_channels = list(resnet.children())[-1].in_features
backbone = nn.Sequential(
lightly.models.batchnorm.get_norm_layer... | num_ftrs) | self.assertEqual | variable | tests/models/test_ModelsSimCLR.py | test_feature_dim_configurable | TestModelsSimCLR | 58 | null |
lightly-ai/lightly | import pytest
import torch
from lightly.loss.hypersphere_loss import HypersphereLoss
class TestHyperSphereLoss:
@pytest.mark.parametrize("bsz", range(2, 20))
def test_forward_pass(self, bsz: int) -> None:
loss = HypersphereLoss()
batch_1 = torch.randn((bsz, 32))
batch_2 = torch.randn... | pytest.approx(l2) | assert | func_call | tests/loss/test_hypersphere_loss.py | test_forward_pass | TestHyperSphereLoss | 20 | null |
lightly-ai/lightly | from typing import List
import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_datasets
from lightly.openapi_generated.swagger_client.api import DatasetsApi
from lightly.openapi_generated.swagger_client.models import (
Creator,
DatasetCreateRequest,
Dat... | dataset.type | assert | complex_expr | tests/api_workflow/test_api_workflow_datasets.py | test_dataset_type | 216 | null | |
lightly-ai/lightly | from PIL import Image
from lightly.transforms.fda_transform import (
FDATransform,
FDAView1Transform,
FDAView2Transform,
)
from .. import helpers
def test_view_on_pil_image() -> None:
single_view_transform = FDAView1Transform(input_size=32)
sample = Image.new("RGB", (100, 100))
output = singl... | (3, 32, 32) | assert | collection | tests/transforms/test_fda_transform.py | test_view_on_pil_image | 16 | null | |
lightly-ai/lightly | import unittest
import torch
import torch.nn as nn
import torchvision
import lightly
from lightly.models import BYOL, ResNetGenerator
def get_backbone(resnet, num_ftrs=64):
last_conv_channels = list(resnet.children())[-1].in_features
backbone = nn.Sequential(
lightly.models.batchnorm.get_norm_layer(3... | model) | self.assertIsNotNone | variable | tests/models/test_ModelsBYOL.py | test_create_variations_cpu | TestModelsBYOL | 32 | null |
lightly-ai/lightly | import unittest
from copy import deepcopy
from random import randint, random, seed
from lightly.api.bitmask import BitMask
N = 10
class TestBitMask(unittest.TestCase):
def setup(self, psuccess=1.0):
pass
def assert_difference(self, bistring_1: str, bitstring_2: str, target: str):
mask_a = Bi... | "0b0011") | assert_* | string_literal | tests/api/test_BitMask.py | test_differences | TestBitMask | 101 | null |
lightly-ai/lightly | from typing import List
import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_datasets
from lightly.openapi_generated.swagger_client.api import DatasetsApi
from lightly.openapi_generated.swagger_client.models import (
Creator,
DatasetCreateRequest,
Dat... | [] | assert | collection | tests/api_workflow/test_api_workflow_datasets.py | test_get_datasets_by_name__own_not_existing | TestApiWorkflowDatasets | 85 | null |
lightly-ai/lightly | import pytest
import torch
from PIL import Image as PILImageModule
from PIL.Image import Image as PILImage
from torch.testing import assert_close
from lightly.utils.dependency import torchvision_transforms_v2_available
from torchvision.tv_tensors import BoundingBoxes, Mask
from lightly.transforms import AddGridTrans... | 2 | assert | numeric_literal | tests/transforms/test_add_grid_transform.py | test_AddGridTransform_as_args | 96 | null | |
lightly-ai/lightly | from PIL import Image
from lightly.transforms.msn_transform import MSNTransform, MSNViewTransform
from .. import helpers
def test_view_on_pil_image() -> None:
single_view_transform = MSNViewTransform(crop_size=32)
sample = Image.new("RGB", (100, 100))
output = single_view_transform(sample)
assert ou... | (3, 32, 32) | assert | collection | tests/transforms/test_msn_transform.py | test_view_on_pil_image | 12 | null | |
lightly-ai/lightly | import unittest
from copy import deepcopy
from random import randint, random, seed
from lightly.api.bitmask import BitMask
N = 10
class TestBitMask(unittest.TestCase):
def setup(self, psuccess=1.0):
pass
def assert_difference(self, bistring_1: str, bitstring_2: str, target: str):
mask_a = Bi... | mask_a) | self.assertEqual | variable | tests/api/test_BitMask.py | test_operator_minus | TestBitMask | 131 | null |
lightly-ai/lightly | import unittest
import torch
from lightly.loss import DINOLoss
from lightly.models.modules.heads import (
BarlowTwinsProjectionHead,
BYOLPredictionHead,
BYOLProjectionHead,
DenseCLProjectionHead,
DINOProjectionHead,
DINOv2ProjectionHead,
MMCRProjectionHead,
MoCoProjectionHead,
MSNP... | are_same) | self.assertFalse | variable | tests/models/test_ProjectionHeads.py | test_dino_projection_head_freeze_last_layer | TestProjectionHeads | 228 | null |
lightly-ai/lightly | import pickle
from pytest_mock import MockerFixture
from urllib3 import PoolManager, Timeout
from lightly.api.swagger_rest_client import LightlySwaggerRESTClientObject
from lightly.openapi_generated.swagger_client.configuration import Configuration
class TestLightlySwaggerRESTClientObject:
def test_request__con... | 2 | assert | numeric_literal | tests/api/test_swagger_rest_client.py | test_request__connection_read_timeout | TestLightlySwaggerRESTClientObject | 72 | null |
lightly-ai/lightly | from __future__ import annotations
import copy
import random
import unittest
from typing import Optional
import pytest
import torch
import torch.nn as nn
from pytest_mock import MockerFixture
from torch import Tensor
from torch.nn import Identity, Parameter
from lightly.models import utils
from lightly.models.utils ... | 3 | assert | numeric_literal | tests/models/test_ModelUtils.py | test_random_block_mask_image__aspect_ratio_one | 617 | null | |
lightly-ai/lightly | from pathlib import Path
import pytest
from lightly.api import serve
def test__translate_path(tmp_path: Path) -> None:
tmp_file = tmp_path / "hello/world.txt"
assert serve._translate_path(path="/hello/world.txt", directories=[]) == | "" | assert | string_literal | tests/api/test_serve.py | test__translate_path | 70 | null | |
lightly-ai/lightly | import json
import logging
import time
import pytest
import requests
from pytest_mock import MockerFixture
from requests import Session
from requests.exceptions import RequestException
from urllib3.exceptions import ProtocolError
from urllib3.response import HTTPResponse
from lightly.api import retry_utils
from light... | caplog.text | assert | complex_expr | tests/api/test_retry_utils.py | test_retry__prints_log | 276 | null | |
lightly-ai/lightly | import unittest
import pytest
import torch
import torch.nn.functional as F
from pytest_mock import MockerFixture
from torch import Tensor
from torch import distributed as dist
from lightly.loss import VICRegLoss
class TestVICRegLoss:
def test_forward_pass(self) -> None:
loss = VICRegLoss()
for b... | l2.item()) | pytest.approx | func_call | tests/loss/test_vicreg_loss.py | test_forward_pass | TestVICRegLoss | 39 | null |
lightly-ai/lightly | import unittest
import torch
import torch.nn as nn
import torchvision
import lightly
from lightly.models import ResNetGenerator, SimCLR
def get_backbone(resnet, num_ftrs=64):
last_conv_channels = list(resnet.children())[-1].in_features
backbone = nn.Sequential(
lightly.models.batchnorm.get_norm_layer... | out_dim) | self.assertEqual | variable | tests/models/test_ModelsSimCLR.py | test_feature_dim_configurable | TestModelsSimCLR | 63 | null |
lightly-ai/lightly | from abc import ABC, abstractmethod
from typing import Optional, Tuple
import pytest
import torch
from pytest_mock import MockerFixture
from torch import Tensor
from torch.nn import Parameter
from lightly.models import utils
from lightly.models.modules.masked_vision_transformer import MaskedVisionTransformer
class M... | "learn" | assert | string_literal | tests/models/modules/masked_vision_transformer_test.py | test__init__pos_embed_initialization | MaskedVisionTransformerTest | 60 | null |
lightly-ai/lightly | from typing import Tuple
import pytest
import torch
from pytest_mock import MockerFixture
from pytorch_lightning import Trainer
from torch import Tensor, nn
from torch.utils.data import DataLoader, Dataset
from lightly.utils.benchmarking import KNNClassifier
from lightly.utils.benchmarking.knn_classifier import F
cl... | 3 / 3) | pytest.approx | complex_expr | tests/utils/benchmarking/test_knn_classifier.py | test | TestKNNClassifier | 67 | null |
lightly-ai/lightly | import unittest
from copy import deepcopy
from random import randint, random, seed
from lightly.api.bitmask import BitMask
N = 10
class TestBitMask(unittest.TestCase):
def setup(self, psuccess=1.0):
pass
def test_bitmask_from_length(self):
length = 4
mask = BitMask.from_length(length... | "0b1111") | self.assertEqual | string_literal | tests/api/test_BitMask.py | test_bitmask_from_length | TestBitMask | 34 | null |
lightly-ai/lightly | import unittest
from copy import deepcopy
from random import randint, random, seed
from lightly.api.bitmask import BitMask
N = 10
class TestBitMask(unittest.TestCase):
def setup(self, psuccess=1.0):
pass
def assert_difference(self, bistring_1: str, bitstring_2: str, target: str):
mask_a = Bi... | "0b10011") | assert_* | string_literal | tests/api/test_BitMask.py | test_differences | TestBitMask | 102 | null |
lightly-ai/lightly | import unittest
import torch
import torch.nn as nn
import torchvision
import lightly
from lightly.models import ResNetGenerator, SimCLR
def get_backbone(resnet, num_ftrs=64):
last_conv_channels = list(resnet.children())[-1].in_features
backbone = nn.Sequential(
lightly.models.batchnorm.get_norm_layer... | out) | self.assertIsNotNone | variable | tests/models/test_ModelsSimCLR.py | test_variations_input_dimension | TestModelsSimCLR | 80 | null |
lightly-ai/lightly | from PIL import Image
from lightly.transforms.ibot_transform import IBOTTransform, IBOTViewTransform
from .. import helpers
def test_view_on_pil_image() -> None:
single_view_transform = IBOTViewTransform(crop_size=32)
sample = Image.new("RGB", (100, 100))
output = single_view_transform(sample)
asser... | (3, 32, 32) | assert | collection | tests/transforms/test_ibot_transform.py | test_view_on_pil_image | 12 | null | |
lightly-ai/lightly | import torch
from lightly.transforms import RFFT2DTransform
def test() -> None:
transform = RFFT2DTransform()
image = torch.rand(3, 32, 32)
output = transform(image)
assert output.shape == | (3, 32, 17) | assert | collection | tests/transforms/test_rfft2d_transform.py | test | 10 | null | |
lightly-ai/lightly | import pytest
import torch
from pytest_mock import MockerFixture
from torch import distributed as dist
from lightly.loss.dcl_loss import DCLLoss, DCLWLoss, negative_mises_fisher_weights
class TestDCLLoss:
@pytest.mark.parametrize("batch_size", [2, 3])
@pytest.mark.parametrize("dim", [1, 3])
@pytest.mark.... | pytest.approx(loss1) | assert | func_call | tests/loss/test_dcl_loss.py | test_dclloss_forward | TestDCLLoss | 55 | null |
lightly-ai/lightly | from __future__ import annotations
import contextlib
import io
import os
import shutil
import tempfile
import unittest
from fractions import Fraction
from typing import Any
from unittest import mock
import PIL
import torch
import torchvision
from lightly.data import LightlyDataset, NonIncreasingTimestampError
from l... | desc in printed) | self.assertTrue | complex_expr | tests/data/test_VideoDataset.py | test_video_dataset_tqdm_args | TestVideoDataset | 147 | null |
lightly-ai/lightly | from typing import Optional
import pytest
import torch
from pytest_mock import MockerFixture
from torch.nn import Parameter
from lightly.utils import dependency
from timm.models.vision_transformer import VisionTransformer
from lightly.models.modules import masked_vision_transformer_timm
from lightly.models.modules.... | antialias | assert | variable | tests/models/modules/test_masked_vision_transformer_timm.py | test_add_pos_embed__antialias | TestMaskedVisionTransformerTIMM | 97 | null |
lightly-ai/lightly | import math
import unittest
import numpy as np
import torch
from PIL import Image
from lightly.data import collate
from lightly.utils import debug
BATCH_SIZE = 10
DIMENSION = 10
class TestDebug(unittest.TestCase):
def _generate_random_image(self, w: int, h: int, c: int):
array = np.random.rand(h, w, c) ... | fig) | self.assertIsNotNone | variable | tests/utils/test_debug.py | test_plot_augmented_images_image_collate_function | TestDebug | 58 | null |
lightly-ai/lightly | import json
import random
import re
from typing import Any, List
from unittest import mock
from unittest.mock import MagicMock
import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_compute_worker
from lightly.api.api_workflow_compute_worker import (
STATE_SCH... | True | assert | bool_literal | tests/api_workflow/test_api_workflow_compute_worker.py | test_get_compute_worker_state_and_message_CANCELED | 646 | null | |
lightly-ai/lightly | import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_download_dataset
from lightly.openapi_generated.swagger_client.models import (
DatasetData,
DatasetEmbeddingData,
DatasetType,
ImageType,
TagData,
)
from tests.api_workflow import utils
def ... | None | assert | none_literal | tests/api_workflow/test_api_workflow_download_dataset.py | test__get_latest_default_embedding_data__no_default_embedding | 293 | null | |
lightly-ai/lightly | from PIL import Image
from lightly.transforms.dino_transform import DINOTransform, DINOViewTransform
from .. import helpers
def test_multi_view_on_pil_image() -> None:
multi_view_transform = DINOTransform(global_crop_size=32, local_crop_size=8)
sample = Image.new("RGB", (100, 100))
output = helpers.asser... | 8 | assert | numeric_literal | tests/transforms/test_dino_transform.py | test_multi_view_on_pil_image | 19 | null | |
lightly-ai/lightly | import os
import shutil
import tempfile
import unittest
from typing import List, Tuple
import numpy as np
import torchvision
from PIL.Image import Image
from lightly.data import LightlyDataset
from lightly.data._utils import check_images
from lightly.transforms.torchvision_v2_compatibility import torchvision_transfor... | str) | self.assertIsInstance | variable | tests/data/test_LightlyDataset.py | test_filenames_dataset_with_subdir | TestLightlyDataset | 208 | null |
lightly-ai/lightly | import unittest
import torch
import torch.nn as nn
import torchvision
import lightly
from lightly.models import BYOL, ResNetGenerator
def get_backbone(resnet, num_ftrs=64):
last_conv_channels = list(resnet.children())[-1].in_features
backbone = nn.Sequential(
lightly.models.batchnorm.get_norm_layer(3... | num_ftrs) | self.assertEqual | variable | tests/models/test_ModelsBYOL.py | test_feature_dim_configurable | TestModelsBYOL | 58 | null |
lightly-ai/lightly | from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient
from lightly.openapi_generated.swagger_client.models import (
DatasourceConfigAzure,
DatasourceConfigGCS,
DatasourceConfigLOCAL,
DatasourceConfigS3,
DatasourceConfigS3DelegatedAccess,
DatasourcePurpose,
)
from light... | "" | assert | string_literal | tests/api_workflow/test_api_workflow_datasources.py | test_set_local_config | TestDatasourcesMixin | 86 | null |
lightly-ai/lightly | import pytest
import torch
from pytest_mock import MockerFixture
from torch import distributed as dist
from lightly.loss.dcl_loss import DCLLoss, DCLWLoss, negative_mises_fisher_weights
class TestDCLLoss:
@pytest.mark.parametrize("batch_size", [2, 3])
@pytest.mark.parametrize("dim", [1, 3])
@pytest.mark.... | loss1) | pytest.approx | variable | tests/loss/test_dcl_loss.py | test_dclloss_forward | TestDCLLoss | 55 | null |
lightly-ai/lightly | from typing import TYPE_CHECKING
import numpy as np
import pytest
from numpy.testing import assert_allclose
from sklearn.decomposition import PCA as SKPCA
from lightly.utils.embeddings_2d import PCA, fit_pca
def test_fit_pca_invalid_fraction_raises_value_error() -> None:
X = np.random.randn(20, 4).astype(np.flo... | str(excinfo.value) | assert | func_call | tests/utils/test_embeddings_2d.py | test_fit_pca_invalid_fraction_raises_value_error | 64 | null | |
lightly-ai/lightly | import numpy as np
import pytest
import torch
import torch.nn.functional as F
from torch import Tensor
from lightly.loss import MACLLoss
def _cal_macl_loss_original(
pos: Tensor, neg: Tensor, tau_0: float, alpha: float, A0: float
) -> Tensor:
"""The original implementation of the MACL loss.
See: https://... | l2, abs=1e-6) | pytest.approx | complex_expr | tests/loss/test_macl_loss.py | test_with_batch_size_2 | TestMACLLoss | 89 | null |
lightly-ai/lightly | from PIL import Image
from lightly.transforms.pirl_transform import PIRLTransform
from .. import helpers
def test_multi_view_on_pil_image() -> None:
multi_view_transform = PIRLTransform(input_size=32)
sample = Image.new("RGB", (100, 100))
output = helpers.assert_list_tensor(multi_view_transform(sample))
... | (3, 32, 32) | assert | collection | tests/transforms/test_pirl_transform.py | test_multi_view_on_pil_image | 13 | null | |
lightly-ai/lightly | import random
import tempfile
import unittest
from typing import List, Tuple
from lightly.data.dataset import LightlyDataset
from lightly.data.lightly_subset import LightlySubset
from tests.data.test_LightlyDataset import TestLightlyDataset
class TestLightlySubset(TestLightlyDataset):
def setUp(self) -> None:
... | fname | assert | variable | tests/data/test_LightlySubset.py | test_create_lightly_subset | TestLightlySubset | 62 | null |
lightly-ai/lightly | import unittest
from copy import deepcopy
from random import randint, random, seed
from lightly.api.bitmask import BitMask
N = 10
class TestBitMask(unittest.TestCase):
def setup(self, psuccess=1.0):
pass
def test_large_bitmasks(self):
bitstring = "0b" + "1" * 5678
mask = BitMask.from... | bitstring) | self.assertEqual | variable | tests/api/test_BitMask.py | test_large_bitmasks | TestBitMask | 29 | null |
lightly-ai/lightly | import os
import shutil
import tempfile
import unittest
from typing import List, Tuple
import numpy as np
import torchvision
from PIL.Image import Image
from lightly.data import LightlyDataset
from lightly.data._utils import check_images
from lightly.transforms.torchvision_v2_compatibility import torchvision_transfor... | n_corrupt | assert | variable | tests/data/test_LightlyDataset.py | test_check_images | TestLightlyDataset | 159 | null |
lightly-ai/lightly | import numpy as np
import pytest
import torch
from pytest_mock import MockerFixture
from torch import Tensor
from torch import distributed as dist
from lightly.loss import NTXentLoss
class TestNTXentLoss:
@pytest.mark.parametrize("n_samples", [1, 2, 4])
@pytest.mark.parametrize("dimension", [1, 2, 16, 64])
... | l2, abs=1e-5) | pytest.approx | complex_expr | tests/loss/test_ntx_ent_loss.py | test_with_values | TestNTXentLoss | 53 | null |
lightly-ai/lightly | from PIL import Image
from lightly.transforms.simclr_transform import SimCLRTransform, SimCLRViewTransform
from .. import helpers
def test_view_on_pil_image() -> None:
single_view_transform = SimCLRViewTransform(input_size=32)
sample = Image.new("RGB", (100, 100))
output = single_view_transform(sample)
... | (3, 32, 32) | assert | collection | tests/transforms/test_simclr_transform.py | test_view_on_pil_image | 12 | null | |
lightly-ai/lightly | from typing import TYPE_CHECKING
import numpy as np
import pytest
from numpy.testing import assert_allclose
from sklearn.decomposition import PCA as SKPCA
from lightly.utils.embeddings_2d import PCA, fit_pca
def test_fit_pca_helper_behavior() -> None:
X = np.random.randn(50, 5).astype(np.float32)
# Use the ... | (50, 1) | assert | collection | tests/utils/test_embeddings_2d.py | test_fit_pca_helper_behavior | 55 | null | |
lightly-ai/lightly | from typing import List
import pytest
from pytest_mock import MockerFixture
from lightly.active_learning.config.selection_config import SelectionConfig
from lightly.api import ApiWorkflowClient, api_workflow_selection
from lightly.openapi_generated.swagger_client.models import (
JobResultType,
JobState,
J... | tag_id | assert | variable | tests/api_workflow/test_api_workflow_selection.py | test_upload_scores | 229 | null | |
lightly-ai/lightly | import math
import pytest
import torch
from torch import Tensor
from lightly.loss import pmsn_loss
from lightly.loss.pmsn_loss import PMSNCustomLoss, PMSNLoss
def test__power_law_distribution() -> None:
power_dist = pmsn_loss._power_law_distribution(
size=4, exponent=0.5, device=torch.device("cpu")
)... | torch.device("cpu") | assert | func_call | tests/loss/test_pmsn_loss.py | test__power_law_distribution | 95 | null | |
lightly-ai/lightly | import pytest
import torch
import torch.nn as nn
from pytest_mock import MockerFixture
from torch import Tensor
from torch import distributed as dist
from torch.nn import Module
from lightly.loss.barlow_twins_loss import BarlowTwinsLoss
def off_diagonal(x: Tensor) -> Tensor:
# return a flattened view of the off-d... | m | assert | variable | tests/loss/test_barlow_twins_loss.py | off_diagonal | 47 | null | |
lightly-ai/lightly | import unittest
import torch
import torch.nn as nn
import torchvision
from lightly.models import NNCLR
from lightly.models.modules import NNMemoryBankModule
def resnet_generator(name: str):
if name == "resnet18":
return torchvision.models.resnet18()
elif name == "resnet50":
return torchvision... | model) | self.assertIsNotNone | variable | tests/models/test_ModelsNNCLR.py | test_create_variations_cpu | TestNNCLR | 47 | null |
lightly-ai/lightly | import csv
import io
import json
import tempfile
import unittest
from collections import defaultdict
from io import IOBase
from typing import *
import numpy as np
import requests
from requests import Response
import lightly
from lightly.api.api_workflow_client import ApiWorkflowClient
from lightly.openapi_generated.s... | len(self.datasets) - 1 | assert | func_call | tests/api_workflow/mocked_api_workflow_client.py | delete_dataset_by_id | MockedDatasetsApi | 616 | null |
lightly-ai/lightly | from PIL import Image
from lightly.transforms.dino_transform import DINOTransform, DINOViewTransform
from .. import helpers
def test_view_on_pil_image() -> None:
single_view_transform = DINOViewTransform(crop_size=32)
sample = Image.new("RGB", (100, 100))
output = single_view_transform(sample)
asser... | (3, 32, 32) | assert | collection | tests/transforms/test_dino_transform.py | test_view_on_pil_image | 12 | null | |
lightly-ai/lightly | import pytest
import tqdm
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_datasource_listing
from lightly.openapi_generated.swagger_client.models import DatasourceRawSamplesDataRow
from lightly.openapi_generated.swagger_client.models.datasource_processed_until_timestamp_re... | 0 | assert | numeric_literal | tests/api_workflow/test_api_workflow_datasource_listing.py | test__get_divide_and_conquer_list_cursors__with_retry | TestListingMixin | 772 | null |
lightly-ai/lightly | import json
import logging
import time
import pytest
import requests
from pytest_mock import MockerFixture
from requests import Session
from requests.exceptions import RequestException
from urllib3.exceptions import ProtocolError
from urllib3.response import HTTPResponse
from lightly.api import retry_utils
from light... | str(exception.value) | assert | func_call | tests/api/test_retry_utils.py | test_retry_on_requests_error__retry | 33 | null | |
lightly-ai/lightly | from __future__ import annotations
import contextlib
import io
import os
import shutil
import tempfile
import unittest
from fractions import Fraction
from typing import Any
from unittest import mock
import PIL
import torch
import torchvision
from lightly.data import LightlyDataset, NonIncreasingTimestampError
from l... | expected) | self.assertListEqual | variable | tests/data/test_VideoDataset.py | test_find_non_increasing_timestamps | TestVideoDataset | 327 | null |
lightly-ai/lightly | import pytest
import torch
from PIL import Image as PILImageModule
from PIL.Image import Image as PILImage
from torch.testing import assert_close
from lightly.utils.dependency import torchvision_transforms_v2_available
from torchvision.tv_tensors import BoundingBoxes, Mask
from lightly.transforms import AddGridTrans... | bbox_tr) | assert_* | variable | tests/transforms/test_add_grid_transform.py | test_AddGridTransform_bbox | 53 | null | |
lightly-ai/lightly | from typing import List, Tuple, Union
from warnings import warn
import torch
from torch import Tensor
from lightly.data.multi_view_collate import MultiViewCollate
def test_single_item_batch():
multi_view_collate = MultiViewCollate()
img = [torch.randn((3, 224, 224)) for _ in range(5)]
label = 1
fname... | 5 | assert | numeric_literal | tests/data/test_multi_view_collate.py | test_single_item_batch | 26 | null | |
lightly-ai/lightly | import os
import re
import shutil
import tempfile
import unittest
import numpy as np
import pytest
import torchvision
from lightly.core import train_model_and_embed_images
class TestCore(unittest.TestCase):
def ensure_dir(self, path_to_folder: str):
if not os.path.exists(path_to_folder):
os.m... | str) | self.assertIsInstance | variable | tests/core/test_Core.py | test_train_and_embed | TestCore | 63 | null |
lightly-ai/lightly | import unittest
from copy import deepcopy
from random import randint, random, seed
from lightly.api.bitmask import BitMask
N = 10
class TestBitMask(unittest.TestCase):
def setup(self, psuccess=1.0):
pass
def assert_difference(self, bistring_1: str, bitstring_2: str, target: str):
mask_a = Bi... | int(target, 2)) | self.assertEqual | func_call | tests/api/test_BitMask.py | assert_difference | TestBitMask | 97 | null |
lightly-ai/lightly | import unittest
import pytest
import torch
import torch.nn.functional as F
from pytest_mock import MockerFixture
from torch import Tensor
from torch import distributed as dist
from lightly.loss import VICRegLoss
def off_diagonal(x: Tensor) -> Tensor:
n, m = x.shape
assert n == | m | assert | variable | tests/loss/test_vicreg_loss.py | off_diagonal | 96 | null | |
lightly-ai/lightly | import torch
from lightly.transforms import IRFFT2DTransform, PhaseShiftTransform, RFFT2DTransform
def test() -> None:
image = torch.randn(3, 64, 64)
rfftTransform = RFFT2DTransform()
rfft = rfftTransform(image)
phaseShiftTf_1 = PhaseShiftTransform()
rescaled_rfft_1 = phaseShiftTf_1(rfft)
p... | rfft.shape | assert | complex_expr | tests/transforms/test_phase_shift_transform.py | test | 25 | null | |
lightly-ai/lightly | import unittest
from copy import deepcopy
from random import randint, random, seed
from lightly.api.bitmask import BitMask
N = 10
class TestBitMask(unittest.TestCase):
def setup(self, psuccess=1.0):
pass
def assert_difference(self, bistring_1: str, bitstring_2: str, target: str):
mask_a = Bi... | "0b100") | assert_* | string_literal | tests/api/test_BitMask.py | test_differences | TestBitMask | 100 | null |
lightly-ai/lightly | from __future__ import annotations
import contextlib
import io
import os
import shutil
import tempfile
import unittest
from fractions import Fraction
from typing import Any
from unittest import mock
import PIL
import torch
import torchvision
from lightly.data import LightlyDataset, NonIncreasingTimestampError
from l... | timestamps[1]) | self.assertEqual | complex_expr | tests/data/test_VideoDataset.py | test_video_similar_timestamps_for_different_backends | TestVideoDataset | 121 | null |
lightly-ai/lightly | import os
import shutil
import tempfile
import unittest
from typing import List, Tuple
import numpy as np
import torchvision
from PIL.Image import Image
from lightly.data import LightlyDataset
from lightly.data._utils import check_images
from lightly.transforms.torchvision_v2_compatibility import torchvision_transfor... | Image) | self.assertIsInstance | variable | tests/data/test_LightlyDataset.py | test_filenames_dataset_with_subdir | TestLightlyDataset | 205 | null |
lightly-ai/lightly | from __future__ import annotations
import copy
import random
import unittest
from typing import Optional
import pytest
import torch
import torch.nn as nn
from pytest_mock import MockerFixture
from torch import Tensor
from torch.nn import Identity, Parameter
from lightly.models import utils
from lightly.models.utils ... | 1 | assert | numeric_literal | tests/models/test_ModelUtils.py | test_get_weight_decay_parameters__nested | 809 | null | |
lightly-ai/lightly | from typing import List
import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_datasets
from lightly.openapi_generated.swagger_client.api import DatasetsApi
from lightly.openapi_generated.swagger_client.models import (
Creator,
DatasetCreateRequest,
Dat... | 3 | assert | numeric_literal | tests/api_workflow/test_api_workflow_datasets.py | test_get_datasets__shared_None | 277 | null | |
lightly-ai/lightly | import os
import unittest
from unittest import mock
import pytest
from PIL import Image
from lightly.api.utils import (
DatasourceType,
PIL_to_bytes,
get_lightly_server_location_from_env,
get_signed_url_destination,
getenv,
paginate_endpoint,
)
class TestUtils(unittest.TestCase):
def tes... | 4 * page_size) | self.assertEqual | complex_expr | tests/api/test_utils.py | test_paginate_endpoint__multiple_of_page_size | TestUtils | 127 | null |
lightly-ai/lightly | import unittest
from copy import deepcopy
from random import randint, random, seed
from lightly.api.bitmask import BitMask
N = 10
class TestBitMask(unittest.TestCase):
def setup(self, psuccess=1.0):
pass
def assert_difference(self, bistring_1: str, bitstring_2: str, target: str):
mask_a = Bi... | "0") | self.assertEqual | string_literal | tests/api/test_BitMask.py | test_invert | TestBitMask | 181 | null |
lightly-ai/lightly | import unittest
from copy import deepcopy
from random import randint, random, seed
from lightly.api.bitmask import BitMask
N = 10
class TestBitMask(unittest.TestCase):
def setup(self, psuccess=1.0):
pass
def test_inverse(self):
# TODO: proper implementation
return
x = int("0... | y) | self.assertEqual | variable | tests/api/test_BitMask.py | test_inverse | TestBitMask | 51 | null |
lightly-ai/lightly | import re
import unittest
import pytest
import torch
from lightly.models.modules.memory_bank import MemoryBankModule
class TestMemoryBank:
def test_forward__dim_first(self) -> None:
torch.manual_seed(0)
memory_bank = MemoryBankModule(size=(5, 2), feature_dim_first=True)
x0 = torch.randn(... | (2, 5) | assert | collection | tests/models/modules/test_memory_bank.py | test_forward__dim_first | TestMemoryBank | 157 | null |
lightly-ai/lightly | import random
import unittest
import torch
import torchvision
from lightly.data import (
BaseCollateFunction,
ImageCollateFunction,
MultiCropCollateFunction,
PIRLCollateFunction,
SimCLRCollateFunction,
SwaVCollateFunction,
)
from lightly.data.collate import (
DINOCollateFunction,
MAECo... | len(fnames)) | self.assertEqual | func_call | tests/data/test_data_collate.py | test_base_collate | TestDataCollate | 50 | null |
lightly-ai/lightly | import os
import shutil
import tempfile
import unittest
from typing import List, Tuple
import numpy as np
import torchvision
from PIL.Image import Image
from lightly.data import LightlyDataset
from lightly.data._utils import check_images
from lightly.transforms.torchvision_v2_compatibility import torchvision_transfor... | len(dataset)) | self.assertEqual | func_call | tests/data/test_LightlyDataset.py | test_create_lightly_dataset_from_folder | TestLightlyDataset | 108 | null |
lightly-ai/lightly | import torch
from lightly.transforms import AmplitudeRescaleTransform, RFFT2DTransform
def test() -> None:
image = torch.randn(3, 64, 64)
rfftTransform = RFFT2DTransform()
rfft = rfftTransform(image)
ampRescaleTf_1 = AmplitudeRescaleTransform()
rescaled_rfft_1 = ampRescaleTf_1(rfft)
ampResc... | rfft.shape | assert | complex_expr | tests/transforms/test_amplitude_rescale_transform.py | test | 20 | null | |
lightly-ai/lightly | import json
import random
import re
from typing import Any, List
from unittest import mock
from unittest.mock import MagicMock
import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_compute_worker
from lightly.api.api_workflow_compute_worker import (
STATE_SCH... | ["label-1"] | assert | collection | tests/api_workflow/test_api_workflow_compute_worker.py | test_get_compute_workers | TestApiWorkflowComputeWorker | 176 | null |
lightly-ai/lightly | from typing import List
import pytest
from pytest_mock import MockerFixture
from lightly.api import ApiWorkflowClient, api_workflow_datasets
from lightly.openapi_generated.swagger_client.api import DatasetsApi
from lightly.openapi_generated.swagger_client.models import (
Creator,
DatasetCreateRequest,
Dat... | dataset_id | assert | variable | tests/api_workflow/test_api_workflow_datasets.py | test_set_dataset_id__warning_not_shared | 425 | null | |
lightly-ai/lightly | import random
import unittest
import torch
import torchvision
from lightly.data import (
BaseCollateFunction,
ImageCollateFunction,
MultiCropCollateFunction,
PIRLCollateFunction,
SimCLRCollateFunction,
SwaVCollateFunction,
)
from lightly.data.collate import (
DINOCollateFunction,
MAECo... | collate) | self.assertIsNotNone | variable | tests/data/test_data_collate.py | test_base_collate | TestDataCollate | 48 | null |
lightly-ai/lightly | from PIL import Image
from lightly.transforms.moco_transform import MoCoV1Transform, MoCoV2Transform
from .. import helpers
def test_moco_v1_multi_view_on_pil_image() -> None:
multi_view_transform = MoCoV1Transform(input_size=32)
sample = Image.new("RGB", (100, 100))
output = helpers.assert_list_tensor(m... | (3, 32, 32) | assert | collection | tests/transforms/test_moco_transform.py | test_moco_v1_multi_view_on_pil_image | 13 | null | |
lightly-ai/lightly | from typing import List, Tuple, Union
from warnings import warn
import torch
from torch import Tensor
from lightly.data.multi_view_collate import MultiViewCollate
def test_empty_batch():
multi_view_collate = MultiViewCollate()
batch = []
views, labels, fnames = multi_view_collate(batch)
assert len(v... | 0 | assert | numeric_literal | tests/data/test_multi_view_collate.py | test_empty_batch | 14 | null | |
nat-n/poethepoet | poetry_vars = {"POETRY_VIRTUALENVS_CREATE": "false"}
def test_setting_default_task_type(run_poe_subproc, projects, esc_prefix):
# Also tests passing of extra_args to sys.argv
result = run_poe_subproc(
"echo-args",
"nat,",
r"welcome to " + esc_prefix + "${POE_ROOT}",
project="scr... | f"Poe => echo-args nat, 'welcome to {projects['scripts']}'\n" | assert | string_literal | tests/test_poe_config.py | test_setting_default_task_type | 16 | null | |
nat-n/poethepoet | def test_task_envfile_and_default(run_poe_subproc):
result = run_poe_subproc("deploy-prod", project="envfile")
assert (
"Poe => poe_test_echo 'deploying to admin:12345@prod.example.com/app'\n"
in result.capture
)
assert result.stdout == | "deploying to admin:12345@prod.example.com/app\n" | assert | string_literal | tests/test_envfile.py | test_task_envfile_and_default | 17 | null | |
nat-n/poethepoet | import os
from pathlib import Path
from shutil import rmtree
import pytest
from poethepoet.scripts import rm
_test_file_tree = {
"pkg": {
"__pycache__": {"foo.pyc": "XXX"},
"foo.py": "XXX",
"bar": {
"baz.py": "XXX",
"__pycache__": {"baz.pyc": "XXX"},
},
... | "Deleting paths matching './**/__pycache__'\n" | assert | string_literal | tests/test_scripts.py | test_rm_dry_mode | 73 | null | |
nat-n/poethepoet | import re
from poethepoet import __version__
poetry_vars = {"POETRY_VIRTUALENVS_CREATE": "false"}
def test_poe_env_vars_are_set(run_poe_subproc):
result = run_poe_subproc("show_env", env=poetry_vars)
assert result.capture == "Poe => poe_test_env\n"
for env_var in (
"POE_VERBOSITY=0",
"POE... | result.stdout | assert | complex_expr | tests/test_cli.py | test_poe_env_vars_are_set | 147 | null | |
nat-n/poethepoet | import pytest
@pytest.mark.flaky(reruns=3, reruns_delay=1)
def test_list_inside_sequence_is_parallel(run_poe_subproc, esc_prefix, delay_factor):
base = 50 * delay_factor
d0, d1, d2 = 0, base, 2 * base
result = run_poe_subproc(
"sequential_parallel",
str(d0),
str(d1),
str(d2)... | "First\n" f"sequential_para… | second {d0}\n" f"sequential_para… | second {d1}\n" f"sequential_para… | second {d2}\n" f"sequential_para… | third {d0}\n" f"sequential_para… | third {d1}\n" f"sequential_para… | third {d2}\n" "Last\n" | assert | string_literal | tests/test_sequence_tasks.py | test_list_inside_sequence_is_parallel | 37 | null | |
nat-n/poethepoet | import os
import shutil
import pytest
def _uv_integration_available():
if not shutil.which("uv"):
return False
try:
import socket
sock = socket.create_connection(("pypi.org", 443), timeout=1)
except OSError:
return False
else:
sock.close()
return True
... | "" | assert | string_literal | tests/test_uv_executor.py | test_uv_package_script_task | 79 | null | |
nat-n/poethepoet | import pytest
def generate_pyproject(temp_pyproject):
def generator(project_verbosity=0, task_verbosity=0):
def inline_task(inline_verbosity: int) -> str:
return (
'{ cmd = "poe_test_echo inline_task '
+ str(inline_verbosity)
+ ' ${POE_VERBOSITY}"... | "task verbosity down\n" | assert | string_literal | tests/test_verbosity.py | test_switch_task_with_verbosity | 198 | null | |
nat-n/poethepoet | def test_customize_config_name(run_poe, projects, capsys):
result = run_poe("hello", config_name="tasks.toml", project="custom_config")
assert result.capture == | "Poe => poe_test_echo hello from tasks.toml\n" | assert | string_literal | tests/test_api.py | test_customize_config_name | 21 | null | |
nat-n/poethepoet | import os
import re
import pytest
def _setup_poetry_project(run_poetry_2, projects):
run_poetry_2(["install"], cwd=projects["poetry_plugin"])
def _setup_poetry_project_empty_prefix(run_poetry_2, projects):
run_poetry_2(
["install"],
cwd=projects["poetry_plugin/empty_prefix"].parent,
)
de... | "Poe => poe_test_echo --lol=:D --version --help\n--lol=:D --version --help\n" | assert | string_literal | tests/test_poetry_plugin_v2.py | test_task_accepts_any_args | 81 | null | |
nat-n/poethepoet | from poethepoet.helpers.command import parse_poe_cmd, resolve_command_tokens
def test_resolve_command_tokens():
line = parse_poe_cmd(
"""
abc${thing1}def *$thing2?
"""
)[0]
assert list(resolve_command_tokens([line], {"thing2": ""})) == | [ ("abcdef", False), ("*?", True), ] | assert | collection | tests/helpers/command/test_command_parsing.py | test_resolve_command_tokens | 11 | null | |
nat-n/poethepoet | import os
import re
import pytest
def _setup_poetry_project(run_poetry_1, projects):
run_poetry_1(["install"], cwd=projects["poetry_plugin"])
def _setup_poetry_project_empty_prefix(run_poetry_1, projects):
run_poetry_1(
["install"],
cwd=projects["poetry_plugin/empty_prefix"].parent,
)
de... | "Poe => poe_test_echo --lol=:D --version --help\n--lol=:D --version --help\n" | assert | string_literal | tests/test_poetry_plugin_v1.py | test_task_accepts_any_args | 81 | null | |
nat-n/poethepoet | import shutil
import subprocess
import pytest
def _bash_is_available() -> bool:
"""Check if bash is actually available and functional."""
bash_path = shutil.which("bash")
if bash_path is None:
return False
try:
proc = subprocess.run(["bash", "--version"], capture_output=True, timeout=5... | 4 | assert | numeric_literal | tests/completion/test_bash_completion.py | test_describe_task_args_output_format | TestTaskArgsOutputFormat | 221 | null |
nat-n/poethepoet | from io import StringIO
import pytest
from poethepoet.helpers.command import parse_poe_cmd
from poethepoet.helpers.command.ast import Glob, PythonGlob, Script
from poethepoet.helpers.command.ast_core import ParseConfig, ParseCursor, ParseError
def test_parse_quotes():
tree = parse_poe_cmd(
"""
x'... | 5 | assert | numeric_literal | tests/helpers/command/test_ast.py | test_parse_quotes | 352 | null | |
nat-n/poethepoet | import shutil
import subprocess
import pytest
def _bash_is_available() -> bool:
"""Check if bash is actually available and functional."""
bash_path = shutil.which("bash")
if bash_path is None:
return False
try:
proc = subprocess.run(["bash", "--version"], capture_output=True, timeout=5... | "/some/path" | assert | string_literal | tests/completion/test_bash_completion_harness.py | test_task_completion_after_c_option | TestBashTaskCompletion | 201 | null |
nat-n/poethepoet | poetry_vars = {"POETRY_VIRTUALENVS_CREATE": "false"}
def test_setting_global_env_vars(run_poe_subproc):
result = run_poe_subproc("travel", env=poetry_vars)
assert ( | "Poe => poe_test_echo 'from EARTH to'\nPoe => 'travel[1]'\n" | assert | string_literal | tests/test_poe_config.py | test_setting_global_env_vars | 36 | null | |
nat-n/poethepoet | import pytest
def generate_pyproject(temp_pyproject):
def generator(project_verbosity=0, task_verbosity=0):
def inline_task(inline_verbosity: int) -> str:
return (
'{ cmd = "poe_test_echo inline_task '
+ str(inline_verbosity)
+ ' ${POE_VERBOSITY}"... | "Poe => poe_test_echo 'cmd task inheriting default verbosity 0 0'\n" "Poe => poe_test_echo inline_task 0 0\n" "Poe => poe_test_echo inline_task 1 1\n" "Poe => poe_test_echo inline_task 2 2\n" | assert | string_literal | tests/test_verbosity.py | test_sequence_task_with_verbosity | 144 | null | |
nat-n/poethepoet | import shutil
import subprocess
import pytest
class TestZshCompletionE2E:
def completion_script(self, run_poe_main):
"""Get the generated zsh completion script."""
result = run_poe_main("_zsh_completion")
return result.stdout
def test_task_completion_with_no_task(self, zsh_harness, c... | "task" | assert | string_literal | tests/completion/test_zsh_completion_harness.py | test_task_completion_with_no_task | TestZshCompletionE2E | 205 | null |
nat-n/poethepoet | import asyncio
import pytest
from poethepoet.helpers.eventloop import async_iter_merge
def _make_async_gen(items, delay: float = 0.001, on_close: asyncio.Event | None = None):
async def _gen():
try:
for item in items:
await asyncio.sleep(delay)
yield item
... | RuntimeError) | pytest.raises | variable | tests/helpers/test_eventloop.py | test_meta_generator_exception_closes_previously_added_sources | 69 | null | |
nat-n/poethepoet | import pytest
def _init_git_submodule(projects):
from poethepoet.helpers.git import GitRepo
repo_path = projects["includes/sub_git_repo/sub_project"].parent.parent
repo = GitRepo(repo_path)
# Init the git repo for use in tests
repo.init()
yield
# Delete the .git dir so that we don't have ... | "" | assert | string_literal | tests/test_includes.py | test_docs_for_include_toml_file | 27 | null | |
nat-n/poethepoet | def test_call_attr_func(run_poe_subproc):
result = run_poe_subproc("deep-graph-with-args", project="graphs")
asse | "Poe => poe_test_echo here we go...\n" "Poe => :\n" "Poe <= poe_test_echo about\n" "Poe <= poe_test_echo hello\n" "Poe => poe_test_echo Thinking about and\n" "Poe => poe_test_echo hello and hello\n" | assert | string_literal | tests/test_graph_execution.py | test_call_attr_func | 3 | null | |
nat-n/poethepoet | import asyncio
import pytest
from poethepoet.helpers.eventloop import async_iter_merge
def _make_async_gen(items, delay: float = 0.001, on_close: asyncio.Event | None = None):
async def _gen():
try:
for item in items:
await asyncio.sleep(delay)
yield item
... | expected | assert | variable | tests/helpers/test_eventloop.py | test_many_sources_preserve_per_source_order | 102 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.