<commit_before>from __future__ import print_function, absolute_import

import json
import sys
from imp import reload
from io import BytesIO, StringIO

import pytest
import yaml

from adr import formatter
from adr.query import format_query, run_query, query_activedata
from adr.util.config import Configuration

if sys.version_info > (3, 0):
    IO = StringIO
else:
    IO = BytesIO

@pytest.fixture
def config():
    congif = Configuration()
    config.debug = False
    config.fmt = 'json'
    config.url = "http://activedata.allizom.org/query"
    return config

def test_query(query_test, config):
    module = 'adr.queries.{}'.format(query_test['query'])
    if module in sys.modules:
        reload(sys.modules[module])

    result = json.loads(format_query(query_test['query'], config))
    #Line 35 - having trouble converting format as when in terminal the 
    #following error appears:
    #TypeError: expected string or buffer
    #It could be because config is an object? Not sure how to resolve...
    
    buf = IO()
    yaml.dump(result, buf)
    print("Yaml formatted result for copy/paste:")
    print(buf.getvalue())

    buf = IO()
    yaml.dump(query_test['expected'], buf)
    print("\nYaml formatted expected:")
    print(buf.getvalue())
    assert result == query_test['expected']<commit_msg>Editted typo in notes for test_queries.py<commit_after>from __future__ import print_function, absolute_import

import json
import sys
from imp import reload
from io import BytesIO, StringIO

import pytest
import yaml

from adr import formatter
from adr.query import format_query, run_query, query_activedata
from adr.util.config import Configuration

if sys.version_info > (3, 0):
    IO = StringIO
else:
    IO = BytesIO

@pytest.fixture
def config():
    congif = Configuration()
    config.debug = False
    config.fmt = 'json'
    config.url = "http://activedata.allizom.org/query"
    return config

def test_query(query_test, config):
    module = 'adr.queries.{}'.format(query_test['query'])
    if module in sys.modules:
        reload(sys.modules[module])

    result = json.loads(format_query(query_test['query'], config))
    #Line 33 - having trouble converting format to json as in terminal the 
    #following error appears:
    #TypeError: expected string or buffer
    #It could be because config is an object? Not sure how to resolve...
    
    buf = IO()
    yaml.dump(result, buf)
    print("Yaml formatted result for copy/paste:")
    print(buf.getvalue())

    buf = IO()
    yaml.dump(query_test['expected'], buf)
    print("\nYaml formatted expected:")
    print(buf.getvalue())
    assert result == query_test['expected']
{'fraction_non_alphanumeric': 0.10259301014656144, 'fraction_numerical': 0.003006388575723412, 'mean_word_length': 3.7031802120141344, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4472048', 'n_tokens_mistral': 830, 'n_tokens_neox': 799, 'n_words': 253}