<commit_before>import json
import os
import unittest

from pyramid import testing

from pyramid_raml import apidef

from .base import DATA_DIR

def get_api(which='test-api.raml'):
    path = os.path.join(DATA_DIR, which)
    return apidef.RamlApiDefinition(path)

def test_base():
    api = get_api()
    assert api.raml != None
    assert api.base_uri == 'http://{apiUri}/api/v1'
    assert api.base_path == '/api/v1'

def test_notexisting_resources():
    api = get_api()
    assert len(list(api.get_resources('/foo'))) == 0
    assert list(api.get_resources('/books'))[0] == api.raml.resources[0]

def test_filtered_resources():
    api = get_api('test-errors-api.raml')
    assert len(list(api.get_resources('/foo'))) == 1
    assert len(list(api.get_resources('/bar'))) == 1

def test_all_resources():
    api = get_api('test-errors-api.raml')
    assert len(list(api.get_resources())) == 3

def test_schema():
    api = get_api()
    resource = list(api.get_resources('/books'))[0]
    body = resource.body[0]
    assert api.get_schema(body, 'application/json') is None

    resource = list(api.get_resources('/books'))[1]
    body = resource.body[0]
    schema = json.load(open(os.path.join(DATA_DIR, 'schemas', 'BookRecord.json')))
    assert api.get_schema(body, 'application/json') == schema

def test_existing_traits():
    api = get_api()
    trait = api.get_trait('sorted')
    assert trait is not None
    assert str(trait.description) == 'A sorted collection resource'
    assert len(trait.query_params) == len(api.raml.traits[0].query_params)

    trait = api.get_trait('paged')
    assert trait is not None
    assert str(trait.description) == 'A paged collection resource'
    assert len(trait.query_params) == len(api.raml.traits[1].query_params)

def test_notexisting_traits():
    api = get_api()
    trait = api.get_trait('foo')
    assert trait is None

def test_empty_traits():<commit_msg>fixed test_schema test<commit_after>import json
import os
import unittest

from pyramid import testing

from pyramid_raml import apidef

from .base import DATA_DIR

def get_api(which='test-api.raml'):
    path = os.path.join(DATA_DIR, which)
    return apidef.RamlApiDefinition(path)

def test_base():
    api = get_api()
    assert api.raml != None
    assert api.base_uri == 'http://{apiUri}/api/v1'
    assert api.base_path == '/api/v1'

def test_notexisting_resources():
    api = get_api()
    assert len(list(api.get_resources('/foo'))) == 0
    assert list(api.get_resources('/books'))[0] == api.raml.resources[0]

def test_filtered_resources():
    api = get_api('test-errors-api.raml')
    assert len(list(api.get_resources('/foo'))) == 1
    assert len(list(api.get_resources('/bar'))) == 1

def test_all_resources():
    api = get_api('test-errors-api.raml')
    assert len(list(api.get_resources())) == 3

def test_schema():
    api = get_api()
    assert api.get_schema(None, 'application/json') is None

    resource = list(api.get_resources('/books'))[1]
    body = resource.body[0]
    schema = json.load(open(os.path.join(DATA_DIR, 'schemas', 'BookRecord.json')))
    assert api.get_schema(body, 'application/json') == schema

def test_existing_traits():
    api = get_api()
    trait = api.get_trait('sorted')
    assert trait is not None
    assert str(trait.description) == 'A sorted collection resource'
    assert len(trait.query_params) == len(api.raml.traits[0].query_params)

    trait = api.get_trait('paged')
    assert trait is not None
    assert str(trait.description) == 'A paged collection resource'
    assert len(trait.query_params) == len(api.raml.traits[1].query_params)

def test_notexisting_traits():
    api = get_api()
    trait = api.get_trait('foo')
    assert trait is None

def test_empty_traits():
{'fraction_non_alphanumeric': 0.1440745672436751, 'fraction_numerical': 0.006924101198402131, 'mean_word_length': 4.103260869565218, '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': '5408496', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1273, 'n_words': 273}