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 |
|---|---|---|---|---|---|---|---|---|---|
DHI/terracotta | import pytest
import sys
from textwrap import dedent
import numpy as np
OPERANDS = {
"v1": np.ma.masked_array(np.arange(1, 6), dtype="float64"),
"v2": np.ma.masked_array(
2 * np.arange(1, 6), dtype="float64", mask=np.array([1, 1, 1, 0, 0])
),
}
VALID_EXPR = (
# identity
("v1", OPERANDS["... | str(raised_exc.value) | assert | func_call | tests/test_expressions.py | test_invalid_expression | 174 | null | |
DHI/terracotta | import pytest
import numpy as np
def reload_cmap():
import importlib
import terracotta.cmaps.get_cmaps
try:
yield
finally:
importlib.reload(terracotta.cmaps.get_cmaps)
def test_get_cmap_filesystem(monkeypatch):
import importlib
import importlib.resources
import terracott... | "monkeypatched" | assert | string_literal | tests/cmaps/test_get_cmap.py | test_get_cmap_filesystem | 42 | null | |
DHI/terracotta | from marshmallow import ValidationError
import pytest
from terracotta.server.singleband import SinglebandOptionSchema
from terracotta.server.rgb import RGBOptionSchema
@pytest.mark.parametrize(
"args, expected",
[("[0, 1]", [0, 1]), ('["p2", "p28"]', ["p2", "p28"]), (None, None)],
)
def test_serde(args, expec... | expected | assert | variable | tests/server/test_fields.py | test_serde | 16 | null | |
DHI/terracotta | import pytest
from PIL import Image
import numpy as np
def test_array_to_png_rgb():
from terracotta import image
testdata = np.random.randint(0, 256, size=(256, 512, 3), dtype="uint8")
out_img = Image.open(image.array_to_png(testdata)).convert("RGBA")
out_data = np.asarray(out_img)
assert out_d... | testdata.shape[:-1] | assert | complex_expr | tests/test_image.py | test_array_to_png_rgb | 43 | null | |
DHI/terracotta | import pytest
from PIL import Image
import numpy as np
def test_array_to_png_singleband():
from terracotta import image
testdata = np.random.randint(0, 256, size=(256, 512), dtype="uint8")
out_img = Image.open(image.array_to_png(testdata)).convert("RGBA")
out_data = np.asarray(out_img)
assert o... | testdata.shape | assert | complex_expr | tests/test_image.py | test_array_to_png_singleband | 14 | null | |
DHI/terracotta | from PIL import Image
import numpy as np
import pytest
from terracotta import exceptions
def test_rgb_out_of_bounds(use_testdb, raster_file):
import terracotta
from terracotta.handlers import rgb
with pytest.raises(terracotta.exceptions.TileOutOfBoundsError) as excinfo:
rgb.rgb(["val21", "x"], [... | str(excinfo.value) | assert | func_call | tests/handlers/test_rgb.py | test_rgb_out_of_bounds | 66 | null | |
DHI/terracotta | import json
import pytest
def test_dict_config():
from terracotta import config
settings = config.parse_config({"DRIVER_PATH": "test3"})
assert settings.DRIVER_PATH == "test3"
settings = config.parse_config({"DEFAULT_TILE_SIZE": [100, 100]})
assert settings.DEFAULT_TILE_SIZE == | (100, 100) | assert | collection | tests/test_config.py | test_dict_config | 58 | null | |
DHI/terracotta | from io import BytesIO
import json
import urllib.parse
from PIL import Image
import marshmallow
import numpy as np
import pytest
def flask_app():
from terracotta.server import create_app
return create_app()
def client(flask_app):
with flask_app.test_client() as client:
yield client
def debug_f... | 0 | assert | numeric_literal | tests/server/test_flask_api.py | test_get_datasets_pagination | 158 | null | |
DHI/terracotta | from PIL import Image
import numpy as np
def test_compute_consistency(use_testdb, testdb, raster_file_xyz):
import terracotta
from terracotta.xyz import get_tile_data
from terracotta.handlers import compute
from terracotta.image import to_uint8
settings = terracotta.get_settings()
raw_img = c... | to_uint8(v1 + v2, 0, 10000)) | assert_* | func_call | tests/handlers/test_compute.py | test_compute_consistency | 46 | null | |
DHI/terracotta | import pytest
from click.testing import CliRunner
import os
import shutil
TEST_CASES = (
{ # basic
"filenames": ["foo.tif"],
"input_pattern": "{name}.tif",
"expected_keys": ["name"],
"expected_datasets": [("foo",)],
},
{ # two keys
"filenames": ["S2_20180101_B04.t... | 1 | assert | numeric_literal | tests/scripts/test_ingest.py | _assert_datasets_equal | 181 | null | |
DHI/terracotta | import json
import pytest
def test_deprecation_behaviour(monkeypatch):
from terracotta import config, exceptions, get_settings, update_settings
for deprecated_field, new_field in config.DEPRECATION_MAP.items():
with monkeypatch.context() as m:
m.setenv(f"TC_{deprecated_field}", "foo")
... | str(warning[0]) | assert | func_call | tests/test_config.py | test_deprecation_behaviour | 96 | null | |
DHI/terracotta | from click.testing import CliRunner
def parse_version(verstr):
"""Convert 'v<major>.<minor>.<patch>' to (major, minor, patch)"""
components = verstr.split(".")
components[0] = components[0].lstrip("v")
return tuple(int(c) for c in components[:3])
def migration_testfunc(v07_db, raster_file):
import... | 0 | assert | numeric_literal | tests/scripts/test_migrate.py | migration_testfunc | 33 | null | |
DHI/terracotta | import pytest
TESTABLE_DRIVERS = ["sqlite", "mysql", "postgresql"]
DRIVER_CLASSES = {
"sqlite": "SQLiteMetaStore",
"sqlite-remote": "SQLiteRemoteMetaStore",
"mysql": "MySQLMetaStore",
"postgresql": "PostgreSQLMetaStore",
}
def test_normalize_base(tmpdir):
from terracotta.drivers import MetaStore
... | str(tmpdir) | assert | func_call | tests/drivers/test_drivers.py | test_normalize_base | 25 | null | |
DHI/terracotta | import pytest
import time
from moto import mock_aws
from moto.xray import XRaySegment
@mock_aws
def run_test():
from terracotta import update_settings
import terracotta.profile
update_settings(XRAY_PROFILE=True)
with XRaySegment():
with pytest.raises(NotImplement... | "foo" | assert | string_literal | tests/test_profile.py | run_test | 54 | null | |
DHI/terracotta | from click.testing import CliRunner
def test_connect(test_server):
from terracotta.scripts import cli
runner = CliRunner()
result = runner.invoke(cli.cli, ["connect", test_server, "--no-browser"])
assert result.exit_code == | 0 | assert | numeric_literal | tests/scripts/test_connect.py | test_connect | 9 | null | |
DHI/terracotta | from io import BytesIO
import json
import urllib.parse
from PIL import Image
import marshmallow
import numpy as np
import pytest
def flask_app():
from terracotta.server import create_app
return create_app()
def client(flask_app):
with flask_app.test_client() as client:
yield client
def debug_f... | 4 | assert | numeric_literal | tests/server/test_flask_api.py | test_get_datasets | 148 | null | |
DHI/terracotta | import pytest
from PIL import Image
import numpy as np
def test_array_to_png_singleband_invalid():
from terracotta import image, exceptions
with pytest.raises(exceptions.InvalidArgumentsError) as exc:
image.array_to_png(np.zeros((20, 20)), colormap="unknown")
assert "invalid color map" in | str(exc.value) | assert | func_call | tests/test_image.py | test_array_to_png_singleband_invalid | 25 | null | |
DHI/terracotta | import pytest
from click.testing import CliRunner
import os
import shutil
TEST_CASES = (
{ # basic
"filenames": ["foo.tif"],
"input_pattern": "{name}.tif",
"expected_keys": ["name"],
"expected_datasets": [("foo",)],
},
{ # two keys
"filenames": ["S2_20180101_B04.t... | datasets | assert | variable | tests/scripts/test_ingest.py | _assert_datasets_equal | 182 | null | |
DHI/terracotta | import pytest
import numpy as np
import rasterio
import rasterio.features
from shapely.geometry import shape, MultiPolygon
def geometry_mismatch(shape1, shape2):
"""Compute relative mismatch of two shapes"""
return shape1.symmetric_difference(shape2).area / shape1.union(shape2).area
def convex_hull_exact(src... | 0.05 | assert | numeric_literal | tests/test_raster.py | test_compute_metadata_approximate | 147 | null | |
DHI/terracotta | import json
import pytest
def test_deprecation_behaviour(monkeypatch):
from terracotta import config, exceptions, get_settings, update_settings
for deprecated_field, new_field in config.DEPRECATION_MAP.items():
with monkeypatch.context() as m:
m.setenv(f"TC_{deprecated_field}", "foo")
... | "bar" | assert | string_literal | tests/test_config.py | test_deprecation_behaviour | 108 | null | |
DHI/terracotta | from io import BytesIO
import json
import urllib.parse
from PIL import Image
import marshmallow
import numpy as np
import pytest
def flask_app():
from terracotta.server import create_app
return create_app()
def client(flask_app):
with flask_app.test_client() as client:
yield client
def debug_f... | 3 | assert | numeric_literal | tests/server/test_flask_api.py | test_get_datasets_selective | 194 | null | |
DHI/terracotta | def test_metadata_handler(use_testdb):
from terracotta.handlers import metadata, datasets
ds = datasets.datasets()[0]
md = metadata.metadata(None, ds)
assert md
assert md["metadata"] == ["extra_data"]
md = metadata.metadata(["metadata", "bounds"], ds)
assert md
assert len(md.keys()) =... | 3 | assert | numeric_literal | tests/handlers/test_metadata.py | test_metadata_handler | 11 | null | |
DHI/terracotta | import pytest
from click.testing import CliRunner
ZOOM_XYZ = {"birds-eye": 8, "balanced": 12, "subpixel": 21, "preview": None}
def benchmark_database(big_raster_file_nodata, big_raster_file_mask, tmpdir_factory):
from terracotta import get_driver, update_settings
keys = ["type", "band"]
update_settings(... | 0 | assert | numeric_literal | tests/benchmarks.py | test_bench_optimize_rasters | 172 | null | |
DHI/terracotta | import pytest
import sys
from textwrap import dedent
import numpy as np
OPERANDS = {
"v1": np.ma.masked_array(np.arange(1, 6), dtype="float64"),
"v2": np.ma.masked_array(
2 * np.arange(1, 6), dtype="float64", mask=np.array([1, 1, 1, 0, 0])
),
}
VALID_EXPR = (
# identity
("v1", OPERANDS["... | ValueError) | pytest.raises | variable | tests/test_expressions.py | test_invalid_expression | 171 | null | |
DHI/terracotta | import pytest
import numpy as np
def reload_cmap():
import importlib
import terracotta.cmaps.get_cmaps
try:
yield
finally:
importlib.reload(terracotta.cmaps.get_cmaps)
def test_get_cmap_filesystem(monkeypatch):
import importlib
import importlib.resources
import terracott... | ModuleNotFoundError) | pytest.raises | variable | tests/cmaps/test_get_cmap.py | test_get_cmap_filesystem | 38 | null | |
DHI/terracotta | import logging
def test_logstream(caplog, capsys):
from terracotta import logs
assert logs.use_colors
logger = logs.set_logger("DEBUG")
caplog.set_level("DEBUG", logger="terracotta")
logger.warning("test")
log_out = caplog.records
assert len(log_out) == 1
log_out = log_out[0]
as... | log_out.message | assert | complex_expr | tests/test_logs.py | test_logstream | 16 | null | |
DHI/terracotta | import json
import pytest
def test_env_config_invalid(monkeypatch):
from terracotta import config
with monkeypatch.context() as m:
m.setenv("TC_DEFAULT_TILE_SIZE", "[1") # unbalanced bracket
with pytest.raises( | ValueError) | pytest.raises | variable | tests/test_config.py | test_env_config_invalid | 35 | null | |
DHI/terracotta | import pytest
import numpy as np
import rasterio
import rasterio.features
from shapely.geometry import shape, MultiPolygon
def geometry_mismatch(shape1, shape2):
"""Compute relative mismatch of two shapes"""
return shape1.symmetric_difference(shape2).area / shape1.union(shape2).area
def convex_hull_exact(src... | valid_data.std()) | assert_* | func_call | tests/test_raster.py | test_compute_metadata | 86 | null | |
DHI/terracotta | import pytest
from click.testing import CliRunner
import os
import shutil
TEST_CASES = (
{ # basic
"filenames": ["foo.tif"],
"input_pattern": "{name}.tif",
"expected_keys": ["name"],
"expected_datasets": [("foo",)],
},
{ # two keys
"filenames": ["S2_20180101_B04.t... | ("name",) | assert | collection | tests/scripts/test_ingest.py | test_ingest | 127 | null | |
DHI/terracotta | import os
import tempfile
import time
import uuid
from pathlib import Path
import pytest
from terracotta import exceptions
boto3 = pytest.importorskip("boto3")
moto = pytest.importorskip("moto")
def mock_aws_env(monkeypatch):
with monkeypatch.context() as m:
m.setenv("AWS_DEFAULT_REGION", "us-east-1")
... | exceptions.DatabaseNotWritableError) | pytest.raises | complex_expr | tests/drivers/test_sqlite_remote.py | test_immutability | 150 | null | |
DHI/terracotta | import logging
def test_logstream(caplog, capsys):
from terracotta import logs
assert logs.use_colors
logger = logs.set_logger("DEBUG")
caplog.set_level("DEBUG", logger="terracotta")
logger.warning("test")
log_out = caplog.records
assert len(log_out) == 1
log_out = log_out[0]
ass... | log_out.levelshortname | assert | complex_expr | tests/test_logs.py | test_logstream | 17 | null | |
DHI/terracotta | import pytest
TESTABLE_DRIVERS = ["sqlite", "mysql", "postgresql"]
DRIVER_CLASSES = {
"sqlite": "SQLiteMetaStore",
"sqlite-remote": "SQLiteRemoteMetaStore",
"mysql": "MySQLMetaStore",
"postgresql": "PostgreSQLMetaStore",
}
@pytest.mark.parametrize("provider", TESTABLE_DRIVERS)
def test_use_credentials... | "foo" | assert | string_literal | tests/drivers/test_drivers.py | test_use_credentials_from_settings | 288 | null | |
DHI/terracotta | import os
import warnings
import traceback
import rasterio
import numpy as np
from click.testing import CliRunner
import pytest
def format_exception(result):
return "".join(traceback.format_exception(*result.exc_info))
def tiny_raster_file(unoptimized_raster_file, tmpdir_factory):
tmpdir = tmpdir_factory.m... | str(result.exception) | assert | func_call | tests/scripts/test_optimize_rasters.py | test_exception_in_subprocess | 238 | null | |
DHI/terracotta | import pytest
from click.testing import CliRunner
ZOOM_XYZ = {"birds-eye": 8, "balanced": 12, "subpixel": 21, "preview": None}
def benchmark_database(big_raster_file_nodata, big_raster_file_mask, tmpdir_factory):
from terracotta import get_driver, update_settings
keys = ["type", "band"]
update_settings(... | 200 | assert | numeric_literal | tests/benchmarks.py | test_bench_rgb | 75 | null | |
DHI/terracotta | import os
import warnings
import traceback
import rasterio
import numpy as np
from click.testing import CliRunner
import pytest
def format_exception(result):
return "".join(traceback.format_exception(*result.exc_info))
def tiny_raster_file(unoptimized_raster_file, tmpdir_factory):
tmpdir = tmpdir_factory.m... | 0 | assert | numeric_literal | tests/scripts/test_optimize_rasters.py | test_optimize_rasters | 61 | null | |
DHI/terracotta | import pytest
TESTABLE_DRIVERS = ["sqlite", "mysql", "postgresql"]
DRIVER_CLASSES = {
"sqlite": "SQLiteMetaStore",
"sqlite-remote": "SQLiteRemoteMetaStore",
"mysql": "MySQLMetaStore",
"postgresql": "PostgreSQLMetaStore",
}
@pytest.mark.parametrize("provider", TESTABLE_DRIVERS)
def test_creation(driver... | keys | assert | variable | tests/drivers/test_drivers.py | test_creation | 102 | null | |
DHI/terracotta | from click.testing import CliRunner
def test_connect_invalid_port():
from terracotta.scripts import cli
runner = CliRunner()
result = runner.invoke(cli.cli, ["connect", "localhost:5556", "--no-browser"])
assert result.exit_code != 0
assert "Could not connect" in | result.output | assert | complex_expr | tests/scripts/test_connect.py | test_connect_invalid_port | 38 | null | |
DHI/terracotta | import pytest
import platform
import time
import numpy as np
from terracotta import exceptions
DRIVERS = ["sqlite", "mysql"] # Some database dialects have issues with float precision
METADATA_KEYS = ("bounds", "range", "mean", "stdev", "percentiles", "metadata")
def dynamic_non_writable_db(monkeypatch, driver_pat... | 0 | assert | numeric_literal | tests/drivers/test_raster_drivers.py | test_raster_cache | 377 | null | |
DHI/terracotta | def test_multiple_metadata_handler(use_testdb):
from terracotta.handlers import metadata, datasets
ds = datasets.datasets()
ds1 = list(ds[0].values())
ds2 = list(ds[1].values())
md = metadata.multiple_metadata(None, [ds1, ds2])
assert md
assert md[0]["metadata"] == ["extra_data"]
ass... | 2 | assert | numeric_literal | tests/handlers/test_metadata.py | test_multiple_metadata_handler | 26 | null | |
DHI/terracotta | import pytest
import platform
import time
import numpy as np
from terracotta import exceptions
DRIVERS = ["sqlite", "mysql"] # Some database dialects have issues with float precision
METADATA_KEYS = ("bounds", "range", "mean", "stdev", "percentiles", "metadata")
def dynamic_non_writable_db(monkeypatch, driver_pat... | {} | assert | collection | tests/drivers/test_raster_drivers.py | test_where | 91 | null | |
DHI/terracotta | import pytest
TESTABLE_DRIVERS = ["sqlite", "mysql", "postgresql"]
DRIVER_CLASSES = {
"sqlite": "SQLiteMetaStore",
"sqlite-remote": "SQLiteRemoteMetaStore",
"mysql": "MySQLMetaStore",
"postgresql": "PostgreSQLMetaStore",
}
@pytest.mark.parametrize("provider", TESTABLE_DRIVERS)
def test_invalid_key_typ... | str(exc) | assert | func_call | tests/drivers/test_drivers.py | test_invalid_key_types | 261 | null | |
DHI/terracotta | import pytest
from click.testing import CliRunner
def toml_file(tmpdir_factory):
content = """
DEFAULT_TILE_SIZE = [64, 64]
"""
outfile = tmpdir_factory.mktemp("config").join("tc-config.toml")
with open(outfile, "w") as f:
f.write(content)
return outfile
def test_serve_find_socket(ra... | result.output | assert | complex_expr | tests/scripts/test_serve.py | test_serve_find_socket | 93 | null | |
DHI/terracotta | import pytest
import sys
from textwrap import dedent
import numpy as np
OPERANDS = {
"v1": np.ma.masked_array(np.arange(1, 6), dtype="float64"),
"v2": np.ma.masked_array(
2 * np.arange(1, 6), dtype="float64", mask=np.array([1, 1, 1, 0, 0])
),
}
VALID_EXPR = (
# identity
("v1", OPERANDS["... | np.dtype("int64") | assert | func_call | tests/test_expressions.py | test_out_dtype | 225 | null | |
DHI/terracotta | import pytest
TESTABLE_DRIVERS = ["sqlite", "mysql", "postgresql"]
DRIVER_CLASSES = {
"sqlite": "SQLiteMetaStore",
"sqlite-remote": "SQLiteRemoteMetaStore",
"mysql": "MySQLMetaStore",
"postgresql": "PostgreSQLMetaStore",
}
@pytest.mark.parametrize("provider", TESTABLE_DRIVERS)
def test_broken_connecti... | RuntimeError) | pytest.raises | variable | tests/drivers/test_drivers.py | test_broken_connection | 188 | null | |
DHI/terracotta | import pytest
import numpy as np
import rasterio
import rasterio.features
from shapely.geometry import shape, MultiPolygon
def geometry_mismatch(shape1, shape2):
"""Compute relative mismatch of two shapes"""
return shape1.symmetric_difference(shape2).area / shape1.union(shape2).area
def convex_hull_exact(src... | 1e-6 | assert | numeric_literal | tests/test_raster.py | test_compute_metadata | 96 | null | |
DHI/terracotta | import pytest
from click.testing import CliRunner
def test_entrypoint_exception(monkeypatch, capsys):
import sys
from terracotta.scripts.cli import cli, entrypoint
dummy_error_message = "Dummy error message"
@cli.command("dummy")
def dummy():
raise RuntimeError(dummy_error_message)
w... | 1 | assert | numeric_literal | tests/scripts/test_cli.py | test_entrypoint_exception | 67 | null | |
DHI/terracotta | import pytest
TEST_CASES = {
"{provider}://root@localhost:5000/test": dict(
username="root", password=None, host="localhost", port=5000, database="test"
),
"root@localhost:5000/test": dict(
username="root", password=None, host="localhost", port=5000, database="test"
),
"{provider}:/... | TEST_CASES[case].get(attr, None) | assert | func_call | tests/drivers/test_paths.py | test_path_parsing | 37 | null | |
DHI/terracotta | from marshmallow import ValidationError
import pytest
from terracotta.server.singleband import SinglebandOptionSchema
from terracotta.server.rgb import RGBOptionSchema
@pytest.mark.parametrize(
"args",
["gamma 1 1.5", "sigmoidal r 6 0.5", "gamma r 1.5 sigmoidal 1 8 0.2"],
)
def test_color_transform_singleband... | args["color_transform"] | assert | complex_expr | tests/server/test_fields.py | test_color_transform_singleband_validation | 56 | null | |
DHI/terracotta | import os
import warnings
import traceback
import rasterio
import numpy as np
from click.testing import CliRunner
import pytest
def format_exception(result):
return "".join(traceback.format_exception(*result.exc_info))
def tiny_raster_file(unoptimized_raster_file, tmpdir_factory):
tmpdir = tmpdir_factory.m... | ctime | assert | variable | tests/scripts/test_optimize_rasters.py | test_reoptimize | 206 | null | |
DHI/terracotta | import pytest
import platform
import time
import numpy as np
from terracotta import exceptions
DRIVERS = ["sqlite", "mysql"] # Some database dialects have issues with float precision
METADATA_KEYS = ("bounds", "range", "mean", "stdev", "percentiles", "metadata")
def dynamic_non_writable_db(monkeypatch, driver_pat... | 2 | assert | numeric_literal | tests/drivers/test_raster_drivers.py | test_where | 84 | null | |
DHI/terracotta | from io import BytesIO
import json
import urllib.parse
from PIL import Image
import marshmallow
import numpy as np
import pytest
def flask_app():
from terracotta.server import create_app
return create_app()
def client(flask_app):
with flask_app.test_client() as client:
yield client
def debug_f... | 403 | assert | numeric_literal | tests/server/test_flask_api.py | test_get_metadata_lazily_nonwritable_db | 58 | null | |
DHI/terracotta | from PIL import Image
import numpy as np
import pytest
from terracotta import exceptions
@pytest.mark.parametrize(
"stretch_range_params",
[
["s2", "p98", "Invalid scale value"],
["pp2", "p98", "Invalid percentile value"],
["p", "p98", "Invalid percentile value"],
["2", "p8", ... | str(err.value) | assert | func_call | tests/handlers/test_singleband.py | test_rgb_invalid_percentiles | 227 | null | |
DHI/terracotta | import pytest
from PIL import Image
import numpy as np
def test_array_to_png_singleband_invalid():
from terracotta import image, exceptions
with pytest.raises(exceptions.InvalidArgumentsError) as exc:
image.array_to_png(np.zeros((20, 20)), colormap="unknown")
assert "invalid color map" in str(exc... | ValueError) | pytest.raises | variable | tests/test_image.py | test_array_to_png_singleband_invalid | 31 | null | |
DHI/terracotta | def test_metadata_handler(use_testdb):
from terracotta.handlers import metadata, datasets
ds = datasets.datasets()[0]
md = metadata.metadata(None, ds)
assert md
assert md["metadata"] == | ["extra_data"] | assert | collection | tests/handlers/test_metadata.py | test_metadata_handler | 7 | null | |
drvinceknight/Nashpy | import unittest
import warnings
import numpy as np
from nashpy.algorithms.lemke_howson import lemke_howson
class TestLemkeHowson(unittest.TestCase):
def test_particular_lemke_howson_non_lex(self):
A = np.array([[3, 3], [2, 5], [0, 6]])
B = np.array([[3, 2], [2, 6], [3, 1]])
for label, ou... | all(np.isclose(eq, np.array([1 / 2, 1 / 2])))) | self.assertTrue | func_call | tests/unit/test_lemke_howson.py | test_particular_lemke_howson_non_lex | TestLemkeHowson | 31 | null |
drvinceknight/Nashpy | from hypothesis import given
from hypothesis.extra.numpy import arrays
import numpy as np
import pytest
from nashpy.learning.stochastic_fictitious_play import (
get_distribution_response_to_play_count,
stochastic_fictitious_play,
)
def test_get_distribution_response_to_play_count_2():
np.random.seed(0)
... | 1 | assert | numeric_literal | tests/unit/test_stochastic_fictitious_play.py | test_get_distribution_response_to_play_count_2 | 40 | null | |
drvinceknight/Nashpy | import unittest
import warnings
import numpy as np
from nashpy.algorithms.lemke_howson import lemke_howson
class TestLemkeHowson(unittest.TestCase):
def test_degenerate_lemke_howson_non_lex_raises_warning(self):
"""
This is a degenerate game so the algorithm fails.
This was raised in
... | RuntimeWarning) | self.assertEqual | variable | tests/unit/test_lemke_howson.py | test_degenerate_lemke_howson_non_lex_raises_warning | TestLemkeHowson | 48 | null |
drvinceknight/Nashpy | import unittest
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from nashpy.linalg import Tableau, TableauLex, create_row_tableau, create_col_tableau
class TestTableau(unittest.TestCase):
def test_particular_pivot(self):
tableau = np.array(
[
... | 2) | self.assertEqual | numeric_literal | tests/unit/test_tableau.py | test_particular_pivot | TestTableau | 109 | null |
drvinceknight/Nashpy | import numpy as np
import pytest
from hypothesis import given, settings
from hypothesis.strategies import integers
from hypothesis.extra.numpy import arrays
from nashpy.learning.replicator_dynamics import (
get_derivative_of_fitness,
replicator_dynamics,
get_derivative_of_asymmetric_fitness,
asymmetric... | ValueError) | pytest.raises | variable | tests/unit/test_replicator_dynamics.py | test_replicator_dynamics_with_incorrect_inputs | 1,146 | null | |
drvinceknight/Nashpy | from hypothesis import given
from hypothesis.extra.numpy import arrays
import numpy as np
import pytest
from nashpy.learning.stochastic_fictitious_play import (
get_distribution_response_to_play_count,
stochastic_fictitious_play,
)
def test_stochastic_fictitious_play_given_etha_epsilon():
np.random.seed(0... | 2 | assert | numeric_literal | tests/unit/test_stochastic_fictitious_play.py | test_stochastic_fictitious_play_given_etha_epsilon | 97 | null | |
drvinceknight/Nashpy | import unittest
import warnings
import numpy as np
from hypothesis import given, settings
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
import pytest
import nashpy as nash
import nashpy.learning
class TestGame(unittest.TestCase):
def test_support_enumeration_for_deg_bi_mat... | 4) | self.assertEqual | numeric_literal | tests/unit/test_game.py | test_support_enumeration_for_deg_bi_matrix_game_with_non_deg | TestGame | 259 | null |
drvinceknight/Nashpy | import unittest
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from nashpy.linalg import Tableau, TableauLex, create_row_tableau, create_col_tableau
class TestTableau(unittest.TestCase):
def test_fail_fast_on_no_dropped_label(self):
tableau = Tableau(np.array([... | ValueError) | self.assertRaises | variable | tests/unit/test_tableau.py | test_fail_fast_on_no_dropped_label | TestTableau | 148 | null |
drvinceknight/Nashpy | from hypothesis import given
from hypothesis.extra.numpy import arrays
import numpy as np
import pytest
from nashpy.learning.stochastic_fictitious_play import (
get_distribution_response_to_play_count,
stochastic_fictitious_play,
)
def test_get_distribution_response_to_play_for_bug_reported_by_user():
"""... | ValueError) | pytest.raises | variable | tests/unit/test_stochastic_fictitious_play.py | test_get_distribution_response_to_play_for_bug_reported_by_user | 54 | null | |
drvinceknight/Nashpy | import unittest
import numpy as np
from nashpy.algorithms.support_enumeration import (
indifference_strategies,
is_ne,
obey_support,
potential_support_pairs,
powerset,
solve_indifference,
)
class TestSupportEnumeration(unittest.TestCase):
def test_obey_support(self):
"""Test for ... | obey_support(np.array([0, 0.5]), np.array([1]))) | self.assertTrue | func_call | tests/unit/test_support_enumeration.py | test_obey_support | TestSupportEnumeration | 235 | null |
drvinceknight/Nashpy | import unittest
import warnings
import numpy as np
from nashpy.algorithms.lemke_howson import lemke_howson
class TestLemkeHowson(unittest.TestCase):
def test_lemke_howson_lex_degenerate_tie_breaking_looping(
self,
):
A = np.array(
[
[0.0, 0.5, 1.0, 1.0, 1.0, 1.0, ... | expected_reward) | self.assertAlmostEqual | variable | tests/unit/test_lemke_howson.py | test_lemke_howson_lex_degenerate_tie_breaking_looping | TestLemkeHowson | 130 | null |
drvinceknight/Nashpy | import unittest
import warnings
import numpy as np
from hypothesis import given, settings
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
import pytest
import nashpy as nash
import nashpy.learning
class TestGame(unittest.TestCase):
@given(A=arrays(np.int8, (4, 5)), B=arrays(... | (A, B)) | self.assertEqual | collection | tests/unit/test_game.py | test_bi_matrix_init | TestGame | 38 | null |
drvinceknight/Nashpy | import unittest
import numpy as np
from nashpy.algorithms.support_enumeration import (
indifference_strategies,
is_ne,
obey_support,
potential_support_pairs,
powerset,
solve_indifference,
)
class TestSupportEnumeration(unittest.TestCase):
def test_obey_support(self):
"""Test for ... | obey_support(np.array([0.5, 0]), np.array([1]))) | self.assertFalse | func_call | tests/unit/test_support_enumeration.py | test_obey_support | TestSupportEnumeration | 232 | null |
drvinceknight/Nashpy | import numpy as np
import nashpy as nash
import nashpy.repeated_games
def test_obtain_strategy_space_after_2_repetition_for_3_by_2_game():
"""
This tests that the output is of the expected format: a dictionary of the
right size (in the case of a 2 by 3 game repeated twice this is
2187 = 3 ^ (1 + 2 * ... | 2187 | assert | numeric_literal | tests/unit/test_repeated_games.py | test_obtain_strategy_space_after_2_repetition_for_3_by_2_game | 115 | null | |
drvinceknight/Nashpy | import unittest
from types import GeneratorType
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
from nashpy.polytope.polytope import (
build_halfspaces,
find_feasible_point,
labels,
non_trivial_vertices,
)
class Test... | np.array_equal(label, expected_label)) | self.assertTrue | func_call | tests/unit/test_polytope.py | test_labelling_of_particular_vertices | TestPolytope | 191 | null |
drvinceknight/Nashpy | import unittest
from types import GeneratorType
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
from nashpy.polytope.polytope import (
build_halfspaces,
find_feasible_point,
labels,
non_trivial_vertices,
)
class Test... | 0) | self.assertGreaterEqual | numeric_literal | tests/unit/test_polytope.py | test_creation_of_non_trivial_vertices | TestPolytope | 127 | null |
drvinceknight/Nashpy | import unittest
from types import GeneratorType
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
from nashpy.polytope.polytope import (
build_halfspaces,
find_feasible_point,
labels,
non_trivial_vertices,
)
class Test... | all( np.isclose( feasible_point, np.array([0.06492189, 0.06492189, 0.06492189]), ) )) | self.assertTrue | func_call | tests/unit/test_polytope.py | test_creation_of_particular_feasible_point | TestPolytope | 96 | null |
drvinceknight/Nashpy | import unittest
import nashpy as nash
class TestVersion(unittest.TestCase):
def test_bi_matrix_init(self):
self.assertIsInstance(nash.__version__, | str) | self.assertIsInstance | variable | tests/unit/test_version.py | test_bi_matrix_init | TestVersion | 12 | null |
drvinceknight/Nashpy | import unittest
from types import GeneratorType
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
from nashpy.polytope.polytope import (
build_halfspaces,
find_feasible_point,
labels,
non_trivial_vertices,
)
class Test... | all(np.isclose(vertex, expected_vertex))) | self.assertTrue | func_call | tests/unit/test_polytope.py | test_creation_of_particular_non_trivial_vertices | TestPolytope | 153 | null |
drvinceknight/Nashpy | import unittest
import numpy as np
from nashpy.algorithms.support_enumeration import (
indifference_strategies,
is_ne,
obey_support,
potential_support_pairs,
powerset,
solve_indifference,
)
class TestSupportEnumeration(unittest.TestCase):
def test_is_ne(self):
"""Test if is ne"""... | is_ne(strategy_pair, support_pair, (A, B))) | self.assertTrue | func_call | tests/unit/test_support_enumeration.py | test_is_ne | TestSupportEnumeration | 256 | null |
drvinceknight/Nashpy | import types
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
from nashpy.learning.fictitious_play import (
fictitious_play,
get_best_response_to_play_count,
update_play_count,
)
def test_find_best_response_to_play_count(... | expected_best_response | assert | variable | tests/unit/test_fictitious_play.py | test_find_best_response_to_play_count | 37 | null | |
drvinceknight/Nashpy | import numpy as np
import nashpy as nash
import nashpy.repeated_games
def test_play_game_with_1_repetitions_for_2_by_2_game():
A = np.array([[0, 1], [2, 3]])
game = nash.Game(A)
expected_utilities = (1.0, -1.0)
utilities = nashpy.repeated_games.play_game(
game,
repetitions=1,
r... | utilities | assert | variable | tests/unit/test_repeated_games.py | test_play_game_with_1_repetitions_for_2_by_2_game | 128 | null | |
drvinceknight/Nashpy | import numpy as np
import nashpy as nash
import nashpy.repeated_games
def test_obtain_strategy_space_after_2_repetition_for_2_by_3_game():
"""
This tests that the output is of the expected format: a dictionary of the
right size (in the case of a 2 by 3 game repeated twice this is
128 = 2 ^ (1 + 2 * 3... | 128 | assert | numeric_literal | tests/unit/test_repeated_games.py | test_obtain_strategy_space_after_2_repetition_for_2_by_3_game | 91 | null | |
drvinceknight/Nashpy | import numpy as np
import nashpy as nash
import nashpy.repeated_games
def test_get_repeated_game_with_2_by_2_stage_game():
"""
Checks the dimension of a repeated game.
TODO More tests needed to check actual value of game.
"""
A = np.array([[0, 11], [-22, 3]])
B = np.array([[2, 1], [-2, -3]])
... | (32, 32) | assert | collection | tests/unit/test_repeated_games.py | test_get_repeated_game_with_2_by_2_stage_game | 201 | null | |
drvinceknight/Nashpy | import unittest
import numpy as np
from nashpy.algorithms.support_enumeration import (
indifference_strategies,
is_ne,
obey_support,
potential_support_pairs,
powerset,
solve_indifference,
)
class TestSupportEnumeration(unittest.TestCase):
def test_indifference_strategies(self):
"... | np.array_equal(obtained, expected)) | self.assertTrue | func_call | tests/unit/test_support_enumeration.py | test_indifference_strategies | TestSupportEnumeration | 180 | null |
drvinceknight/Nashpy | from hypothesis import given
from hypothesis.extra.numpy import arrays
import numpy as np
import pytest
from nashpy.learning.stochastic_fictitious_play import (
get_distribution_response_to_play_count,
stochastic_fictitious_play,
)
def test_stochastic_fictitious_play_2x3():
np.random.seed(0)
iteration... | iterations | assert | variable | tests/unit/test_stochastic_fictitious_play.py | test_stochastic_fictitious_play_2x3 | 138 | null | |
drvinceknight/Nashpy | import unittest
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from nashpy.linalg import Tableau, TableauLex, create_row_tableau, create_col_tableau
class TestTableau(unittest.TestCase):
def test_find_particular_pivot_row(self):
tableau = np.array(
... | row) | self.assertEqual | variable | tests/unit/test_tableau.py | test_find_particular_pivot_row | TestTableau | 73 | null |
drvinceknight/Nashpy | import unittest
import numpy as np
from nashpy.algorithms.support_enumeration import (
indifference_strategies,
is_ne,
obey_support,
potential_support_pairs,
powerset,
solve_indifference,
)
class TestSupportEnumeration(unittest.TestCase):
def test_indifference_strategies(self):
"... | len(expected_indifference)) | self.assertEqual | func_call | tests/unit/test_support_enumeration.py | test_indifference_strategies | TestSupportEnumeration | 178 | null |
drvinceknight/Nashpy | import unittest
from types import GeneratorType
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
from nashpy.polytope.polytope import (
build_halfspaces,
find_feasible_point,
labels,
non_trivial_vertices,
)
class Test... | all(np.dot(M, feasible_point) <= -b)) | self.assertTrue | func_call | tests/unit/test_polytope.py | test_creation_of_feasible_point | TestPolytope | 83 | null |
drvinceknight/Nashpy | import unittest
from types import GeneratorType
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
from nashpy.polytope.polytope import (
build_halfspaces,
find_feasible_point,
labels,
non_trivial_vertices,
)
class Test... | np.array_equal(halfspace, expected_halfspace)) | self.assertTrue | func_call | tests/unit/test_polytope.py | test_creation_of_particular_halfspaces | TestPolytope | 59 | null |
drvinceknight/Nashpy | import unittest
import warnings
import numpy as np
from nashpy.algorithms.lemke_howson import lemke_howson
class TestLemkeHowson(unittest.TestCase):
def test_degenerate_lemke_howson_non_lex_raises_warning(self):
"""
This is a degenerate game so the algorithm fails.
This was raised in
... | 2) | self.assertEqual | numeric_literal | tests/unit/test_lemke_howson.py | test_degenerate_lemke_howson_non_lex_raises_warning | TestLemkeHowson | 45 | null |
drvinceknight/Nashpy | import types
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
from nashpy.learning.fictitious_play import (
fictitious_play,
get_best_response_to_play_count,
update_play_count,
)
@given(
A=arrays(np.int8, (4, 5)),
... | min(tuple(map(len, play_counts))) | assert | func_call | tests/unit/test_fictitious_play.py | test_property_fictitious_play | 59 | null | |
drvinceknight/Nashpy | import types
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
from nashpy.learning.fictitious_play import (
fictitious_play,
get_best_response_to_play_count,
update_play_count,
)
@given(M=arrays(np.int8, (4, 5)))
def test... | 0 | assert | numeric_literal | tests/unit/test_fictitious_play.py | test_property_find_best_response_to_play_count | 23 | null | |
drvinceknight/Nashpy | import numpy as np
from nashpy.linalg.minimax import (
get_A_eq,
get_A_ub,
get_b_ub,
get_bounds,
get_c,
linear_program,
)
def test_get_bounds():
for number_of_rows in range(2, 10):
bounds = get_bounds(number_of_rows)
assert bounds == | [(0, None) for _ in range(number_of_rows)] + [(None, None)] | assert | collection | tests/unit/test_minimax.py | test_get_bounds | 129 | null | |
drvinceknight/Nashpy | import numpy as np
from nashpy.utils.is_best_response import (
is_best_response,
)
def test_is_best_response_example_1():
"""
This tests an example from the discussion documentation.
The second assert checks that the column player strategy is as expected.
"""
A = np.array(((0, -1, 1), (1, 0, ... | False | assert | bool_literal | tests/unit/test_is_best_response.py | test_is_best_response_example_1 | 22 | null | |
drvinceknight/Nashpy | import unittest
from types import GeneratorType
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
from nashpy.polytope.polytope import (
build_halfspaces,
find_feasible_point,
labels,
non_trivial_vertices,
)
class Test... | dimension) | self.assertEqual | variable | tests/unit/test_polytope.py | test_creation_of_non_trivial_vertices | TestPolytope | 125 | null |
drvinceknight/Nashpy | import unittest
import warnings
import numpy as np
from hypothesis import given, settings
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
import pytest
import nashpy as nash
import nashpy.learning
class TestGame(unittest.TestCase):
def test_is_best_response(self):
""... | False | assert | bool_literal | tests/unit/test_game.py | test_is_best_response | TestGame | 585 | null |
drvinceknight/Nashpy | import unittest
import warnings
import numpy as np
from hypothesis import given, settings
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
import pytest
import nashpy as nash
import nashpy.learning
class TestGame(unittest.TestCase):
def test_is_best_response(self):
""... | True | assert | bool_literal | tests/unit/test_game.py | test_is_best_response | TestGame | 584 | null |
drvinceknight/Nashpy | import unittest
import warnings
import numpy as np
from nashpy.algorithms.lemke_howson import lemke_howson
class TestLemkeHowson(unittest.TestCase):
def test_degenerate_lemke_howson_non_lex_raises_warning(self):
"""
This is a degenerate game so the algorithm fails.
This was raised in
... | 4) | self.assertEqual | numeric_literal | tests/unit/test_lemke_howson.py | test_degenerate_lemke_howson_non_lex_raises_warning | TestLemkeHowson | 46 | null |
drvinceknight/Nashpy | import types
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from hypothesis.strategies import integers
from nashpy.learning.fictitious_play import (
fictitious_play,
get_best_response_to_play_count,
update_play_count,
)
@given(M=arrays(np.int8, (4, 5)))
def test... | M.shape[1] - 1 | assert | complex_expr | tests/unit/test_fictitious_play.py | test_property_find_best_response_to_play_count | 24 | null | |
drvinceknight/Nashpy | import unittest
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from nashpy.linalg import Tableau, TableauLex, create_row_tableau, create_col_tableau
class TestTableau(unittest.TestCase):
def test_degenerate_pivot(self):
tableau = TableauLex(
np.arra... | 5) | self.assertEqual | numeric_literal | tests/unit/test_tableau.py | test_degenerate_pivot | TestTableau | 263 | null |
drvinceknight/Nashpy | import unittest
import numpy as np
from hypothesis import given
from hypothesis.extra.numpy import arrays
from nashpy.linalg import Tableau, TableauLex, create_row_tableau, create_col_tableau
class TestTableau(unittest.TestCase):
def test_lex_row_sort(self):
tableau = TableauLex(np.random.rand(3, 3))
... | [0, 2, 1]) | self.assertEqual | collection | tests/unit/test_tableau.py | test_lex_row_sort | TestTableau | 314 | null |
drvinceknight/Nashpy | import unittest
import numpy as np
from nashpy.algorithms.vertex_enumeration import vertex_enumeration
class TestVertexEnumeration(unittest.TestCase):
def test_three_by_two_vertex_enumeration(self):
A = np.array([[3, 3], [2, 5], [0, 6]])
B = np.array([[3, 2], [2, 6], [3, 1]])
expected_e... | all(np.isclose(strategy, expected_strategy))) | self.assertTrue | func_call | tests/unit/test_vertex_enumeration.py | test_three_by_two_vertex_enumeration | TestVertexEnumeration | 35 | null |
drvinceknight/Nashpy | import unittest
import warnings
import numpy as np
from nashpy.algorithms.lemke_howson_lex import lemke_howson_lex
class TestLemkeHowsonLex(unittest.TestCase):
def test_deprecated_lex(self):
A = np.array([[-1, -1, -1], [0, 0, 0], [-1, -1, -10000]])
B = np.array([[-1, -1, -1], [0, 0, 0], [-1, -1,... | 0) | self.assertAlmostEqual | numeric_literal | tests/unit/test_lemke_howson_lex.py | test_deprecated_lex | TestLemkeHowsonLex | 21 | null |
drvinceknight/Nashpy | import unittest
import numpy as np
from nashpy.algorithms.support_enumeration import (
indifference_strategies,
is_ne,
obey_support,
potential_support_pairs,
powerset,
solve_indifference,
)
class TestSupportEnumeration(unittest.TestCase):
def test_potential_supports(self):
"""Test... | 225 | assert | numeric_literal | tests/unit/test_support_enumeration.py | test_potential_supports | TestSupportEnumeration | 114 | null |
drvinceknight/Nashpy | from hypothesis import given
from hypothesis.extra.numpy import arrays
import numpy as np
import pytest
from nashpy.learning.stochastic_fictitious_play import (
get_distribution_response_to_play_count,
stochastic_fictitious_play,
)
def test_stochastic_fictitious_play_default_inputs():
np.random.seed(0)
... | 4 | assert | numeric_literal | tests/unit/test_stochastic_fictitious_play.py | test_stochastic_fictitious_play_default_inputs | 114 | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.