filename
stringlengths
4
198
content
stringlengths
25
939k
environment
sequence
variablearg
sequence
constarg
sequence
variableargjson
stringclasses
1 value
constargjson
stringlengths
2
3.9k
lang
stringclasses
3 values
constargcount
float64
0
129
variableargcount
float64
0
0
sentence
stringclasses
1 value
tests/test.py
import os import sys import pytest import matplotlib.pyplot as plt import numpy as np os.environ["RUNNING_PYTEST"] = "true" import mplhep as hep # noqa """ To test run: py.test --mpl When adding new tests, run: py.test --mpl-generate-path=tests/baseline """ plt.switch_backend("Agg") @pytest.mark.mpl_image_compare(style='default', remove_text=True) def test_basic(): fig, ax = plt.subplots(figsize=(10, 10)) h = [1, 3, 2] bins = [0, 1, 2, 3] hep.histplot(h, bins, yerr=True, label='X') ax.legend() return fig @pytest.mark.mpl_image_compare(style='default', remove_text=True) def test_histplot(): np.random.seed(0) h, bins = np.histogram(np.random.normal(10, 3, 400), bins=10) fig, axs = plt.subplots(2, 2, sharex=True, sharey=True, figsize=(10, 10)) axs = axs.flatten() axs[0].set_title("Default", fontsize=18) hep.histplot(h, bins, ax=axs[0]) axs[1].set_title("Plot Edges", fontsize=18) hep.histplot(h, bins, edges=True, ax=axs[1]) axs[2].set_title("Plot Errorbars", fontsize=18) hep.histplot(h, bins, yerr=np.sqrt(h), ax=axs[2]) axs[3].set_title("Filled Histogram", fontsize=18) hep.histplot(h, bins, histtype='fill', ax=axs[3]) fig.subplots_adjust(hspace=0.1, wspace=0.1) return fig @pytest.mark.mpl_image_compare(style='default', remove_text=True) def test_histplot_density(): np.random.seed(0) h, bins = np.histogram(np.random.normal(10, 3, 400), bins=10) fig, axs = plt.subplots(2, 2, sharex=True, sharey=True, figsize=(10, 10)) axs = axs.flatten() axs[0].set_title("Default", fontsize=18) hep.histplot(h, bins, ax=axs[0], density=True) axs[1].set_title("Plot Edges", fontsize=18) hep.histplot(h, bins, edges=True, ax=axs[1], density=True) axs[2].set_title("Plot Errorbars", fontsize=18) hep.histplot(h, bins, yerr=np.sqrt(h), ax=axs[2], density=True) axs[3].set_title("Filled Histogram", fontsize=18) hep.histplot(h, bins, histtype='fill', ax=axs[3], density=True) fig.subplots_adjust(hspace=0.1, wspace=0.1) return fig @pytest.mark.mpl_image_compare(style='default', remove_text=True) def test_histplot_multiple(): np.random.seed(0) h, bins = np.histogram(np.random.normal(10, 3, 400), bins=10) fig, axs = plt.subplots(2, 2, sharex=True, sharey=True, figsize=(10, 10)) axs = axs.flatten() axs[0].set_title("Default Overlay", fontsize=18) hep.histplot([h, 1.5 * h], bins, ax=axs[0]) axs[1].set_title("Default Overlay w/ Errorbars", fontsize=18) hep.histplot([h, 1.5 * h], bins, yerr=[np.sqrt(h), np.sqrt(1.5 * h)], ax=axs[1]) axs[2].set_title("Automatic Errorbars", fontsize=18) hep.histplot([h, 1.5 * h], bins, yerr=True, ax=axs[2]) axs[3].set_title("With Labels", fontsize=18) hep.histplot([h, 1.5 * h], bins, yerr=True, ax=axs[3], label=["First", "Second"]) axs[3].legend(fontsize=16, prop={'family': 'Tex Gyre Heros'}) fig.subplots_adjust(hspace=0.1, wspace=0.1) return fig @pytest.mark.mpl_image_compare(style='default', remove_text=True) def test_histplot_stack(): np.random.seed(0) h, bins = np.histogram(np.random.normal(10, 3, 400), bins=10) fig, axs = plt.subplots(2, 2, sharex=True, sharey=True, figsize=(10, 10)) axs = axs.flatten() axs[0].set_title("Default", fontsize=18) hep.histplot([h, 1.5 * h], bins, stack=True, ax=axs[0]) axs[1].set_title("Plot Edges", fontsize=18) hep.histplot([h, 1.5 * h], bins, edges=True, stack=True, ax=axs[1]) axs[2].set_title("Plot Errorbars", fontsize=18) hep.histplot([h, 1.5 * h], bins, yerr=np.sqrt(h), stack=True, ax=axs[2]) axs[3].set_title("Filled Histogram", fontsize=18) hep.histplot([1.5 * h, h], bins, histtype='fill', stack=True, ax=axs[3]) fig.subplots_adjust(hspace=0.1, wspace=0.1) return fig @pytest.mark.mpl_image_compare(style='default', remove_text=True) def test_hist2dplot(): np.random.seed(0) xedges = np.arange(0, 11.5, 1.5) yedges = [0, 2, 3, 4, 6, 7] x = np.random.normal(5, 1.5, 100) y = np.random.normal(4, 1, 100) H, xedges, yedges = np.histogram2d(x, y, bins=(xedges, yedges)) fig, ax = plt.subplots() hep.hist2dplot(H, xedges, yedges, labels=True) return fig @pytest.mark.mpl_image_compare(style='default', remove_text=True) def test_histplot_kwargs(): np.random.seed(0) h, bins = np.histogram(np.random.normal(10, 3, 1000), bins=10) fig, axs = plt.subplots(2, 2, sharex=True, sharey=True, figsize=(10, 10)) axs = axs.flatten() hep.histplot([h * 2, h * 1, h * 0.5], bins, label=["1", "2", "3"], stack=True, histtype="step", linestyle="--", color=["green", "black", (1, 0, 0, .4)], ax=axs[0]) axs[0].legend() hep.histplot([h, h, h], bins, label=["1", "2", "3"], stack=True, histtype="step", linestyle=["--", ':'], color=(1, 0, 0, .8), ax=axs[1]) axs[1].legend() hep.histplot([h, h, h], bins, label=["1", "2", "3"], histtype="step", weights=[0.5 * np.ones_like(h), 3 * np.ones_like(h), 6 * np.ones_like(h)], linestyle=["--", ':'], color=(1, 0, 0, .8), ax=axs[2]) axs[2].legend() hep.histplot([h, h, h], bins, label=["1", "2", "3"], histtype="fill", weights=[0.5 * np.ones_like(h), 3 * np.ones_like(h), 6 * np.ones_like(h)], linestyle=["--", ':'], color=["green", "darkorange", 'red'], alpha=[0.4, 0.7, 0.2], ax=axs[3]) axs[3].legend() fig.subplots_adjust(hspace=0.1, wspace=0.1) return fig # Compare styles @pytest.mark.skipif(sys.platform != "linux", reason="Linux only") @pytest.mark.mpl_image_compare(style='default', remove_text=False) def test_style_atlas(): import mplhep as hep import matplotlib.pyplot as plt plt.rcParams.update(plt.rcParamsDefault) # Test suite does not have Helvetica plt.style.use([hep.style.ATLAS, {"font.sans-serif": ["Tex Gyre Heros"]}]) fig, ax = plt.subplots() hep.atlas.text() plt.rcParams.update(plt.rcParamsDefault) return fig @pytest.mark.skipif(sys.platform != "linux", reason="Linux only") @pytest.mark.mpl_image_compare(style='default', remove_text=False) def test_style_cms(): import mplhep as hep import matplotlib.pyplot as plt plt.rcParams.update(plt.rcParamsDefault) plt.style.use(hep.style.CMS) fig, ax = plt.subplots() hep.cms.text() plt.rcParams.update(plt.rcParamsDefault) return fig @pytest.mark.skipif(sys.platform != "linux", reason="Linux only") @pytest.mark.mpl_image_compare(style='default', remove_text=False) def test_style_lhcb(): import mplhep as hep import matplotlib.pyplot as plt plt.rcParams.update(plt.rcParamsDefault) plt.style.use([hep.style.LHCb, {"figure.autolayout": False} ]) fig, ax = plt.subplots() # Doesn't work for now # hep.lhcb.text() plt.rcParams.update(plt.rcParamsDefault) return fig
[]
[]
[ "RUNNING_PYTEST" ]
[]
["RUNNING_PYTEST"]
python
1
0
to_do_list/to_do_list/asgi.py
""" ASGI config for to_do_list project. It exposes the ASGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ """ import os from django.core.asgi import get_asgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'to_do_list.settings') application = get_asgi_application()
[]
[]
[]
[]
[]
python
0
0
tests/base/test_multitenancy.py
# -*- coding: utf-8 -*- from __future__ import absolute_import from __future__ import division from __future__ import print_function from __future__ import unicode_literals import os import tempfile import pytest from treq.testing import StubTreq from rasa_nlu import config from rasa_nlu.config import RasaNLUModelConfig from rasa_nlu.data_router import DataRouter from rasa_nlu.model import Trainer from rasa_nlu.server import RasaNLU from tests.utilities import ResponseTest @pytest.fixture(scope="module") def app(component_builder): """Use IResource interface of Klein to mock Rasa HTTP server. :param component_builder: :return: """ if "TRAVIS_BUILD_DIR" in os.environ: root_dir = os.environ["TRAVIS_BUILD_DIR"] else: root_dir = os.getcwd() _, nlu_log_file = tempfile.mkstemp(suffix="_rasa_nlu_logs.json") train_models(component_builder, os.path.join(root_dir, "data/examples/rasa/demo-rasa.json")) router = DataRouter(os.path.join(root_dir, "test_projects")) rasa = RasaNLU(router, logfile=nlu_log_file, testing=True) return StubTreq(rasa.app.resource()) @pytest.mark.parametrize("response_test", [ ResponseTest( "http://dummy-uri/parse?q=food&project=test_project_mitie", {"entities": [], "intent": "affirm", "text": "food"} ), ResponseTest( "http://dummy-uri/parse?q=food&project=test_project_mitie_sklearn", {"entities": [], "intent": "restaurant_search", "text": "food"} ), ResponseTest( "http://dummy-uri/parse?q=food&project=test_project_spacy_sklearn", {"entities": [], "intent": "restaurant_search", "text": "food"} ), ]) @pytest.inlineCallbacks def test_get_parse(app, response_test): response = yield app.get(response_test.endpoint) rjs = yield response.json() assert response.code == 200 assert all(prop in rjs for prop in ['entities', 'intent', 'text']) @pytest.mark.parametrize("response_test", [ ResponseTest( "http://dummy-uri/parse?q=food", {"error": "No project found with name 'default'."} ), ResponseTest( "http://dummy-uri/parse?q=food&project=umpalumpa", {"error": "No project found with name 'umpalumpa'."} ) ]) @pytest.inlineCallbacks def test_get_parse_invalid_model(app, response_test): response = yield app.get(response_test.endpoint) rjs = yield response.json() assert response.code == 404 assert rjs.get("error").startswith(response_test.expected_response["error"]) @pytest.mark.parametrize("response_test", [ ResponseTest( "http://dummy-uri/parse", {"entities": [], "intent": "affirm", "text": "food"}, payload={"q": "food", "project": "test_project_mitie"} ), ResponseTest( "http://dummy-uri/parse", {"entities": [], "intent": "restaurant_search", "text": "food"}, payload={"q": "food", "project": "test_project_mitie_sklearn"} ), ResponseTest( "http://dummy-uri/parse", {"entities": [], "intent": "restaurant_search", "text": "food"}, payload={"q": "food", "project": "test_project_spacy_sklearn"} ), ]) @pytest.inlineCallbacks def test_post_parse(app, response_test): response = yield app.post(response_test.endpoint, json=response_test.payload) rjs = yield response.json() assert response.code == 200 assert all(prop in rjs for prop in ['entities', 'intent', 'text']) @pytest.inlineCallbacks def test_post_parse_specific_model(app): status = yield app.get("http://dummy-uri/status") sjs = yield status.json() project = sjs["available_projects"]["test_project_spacy_sklearn"] model = project["available_models"][0] query = ResponseTest("http://dummy-uri/parse", {"entities": [], "intent": "affirm", "text": "food"}, payload={"q": "food", "project": "test_project_spacy_sklearn", "model": model}) response = yield app.post(query.endpoint, json=query.payload) assert response.code == 200 # check that that model now is loaded in the server status = yield app.get("http://dummy-uri/status") sjs = yield status.json() project = sjs["available_projects"]["test_project_spacy_sklearn"] assert model in project["loaded_models"] @pytest.mark.parametrize("response_test", [ ResponseTest( "http://dummy-uri/parse", {"error": "No project found with name 'default'."}, payload={"q": "food"} ), ResponseTest( "http://dummy-uri/parse", {"error": "No project found with name 'umpalumpa'."}, payload={"q": "food", "project": "umpalumpa"} ), ]) @pytest.inlineCallbacks def test_post_parse_invalid_model(app, response_test): response = yield app.post(response_test.endpoint, json=response_test.payload) rjs = yield response.json() assert response.code == 404 assert rjs.get("error").startswith(response_test.expected_response["error"]) def train_models(component_builder, data): # Retrain different multitenancy models def train(cfg_name, project_name): from rasa_nlu.train import create_persistor from rasa_nlu import training_data cfg = config.load(cfg_name) trainer = Trainer(cfg, component_builder) training_data = training_data.load_data(data) trainer.train(training_data) trainer.persist("test_projects", project_name=project_name) train("sample_configs/config_spacy.yml", "test_project_spacy_sklearn") train("sample_configs/config_mitie.yml", "test_project_mitie") train("sample_configs/config_mitie_sklearn.yml", "test_project_mitie_sklearn")
[]
[]
[ "TRAVIS_BUILD_DIR" ]
[]
["TRAVIS_BUILD_DIR"]
python
1
0