<commit_before># pylint: disable=no-self-use,invalid-name
import json

from allennlp.service.server_sanic import make_app
from allennlp.service.predictors import load_predictors
from allennlp.common.testing import AllenNlpTestCase


class TestApp(AllenNlpTestCase):

    app = make_app()
    app.predictors = load_predictors()
    app.testing = True
    client = app.test_client

    def test_list_models(self):
        _, response = self.client.get("/models")
        data = json.loads(response.text)
        assert "machine-comprehension" in set(data["models"])

    def test_unknown_model(self):<commit_msg>Make service tests only construct the app when they are run (#136)<commit_after># pylint: disable=no-self-use,invalid-name
import json
import os

from allennlp.service.server_sanic import make_app
from allennlp.service.predictors import load_predictors
from allennlp.common.testing import AllenNlpTestCase


class TestApp(AllenNlpTestCase):

    client = None

    def setUp(self):
        super(TestApp, self).setUp()
        if self.client is None:
            app = make_app()
            app.predictors = load_predictors()
            app.testing = True
            self.client = app.test_client

    def tearDown(self):
        super(TestApp, self).tearDown()
        try:
            os.remove('access.log')
            os.remove('error.log')
        except FileNotFoundError:
            pass

    def test_list_models(self):
        _, response = self.client.get("/models")
        data = json.loads(response.text)
        assert "machine-comprehension" in set(data["models"])

    def test_unknown_model(self):
{'fraction_non_alphanumeric': 0.09637814610190301, 'fraction_numerical': 0.001841620626151013, 'mean_word_length': 3.0852130325814535, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1538861', 'n_tokens_mistral': 493, 'n_tokens_neox': 474, 'n_words': 110}