<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import os.path
import unittest
from mock import patch
from stackapi import StackAPI
from stackapi import StackAPIError


def fake_stackoverflow_exists(self, endpoint=None, page=1, key=None, filter='default', **kwargs):
    response_file = os.path.normpath('mock_objects/test_stackoverflow_exists')
    with open(response_file) as json_file:
        j_data = json.load(json_file)
    return j_data


def fake_users(self, endpoint=None, page=1, key=None, filter='default', **kwargs):
    response_file = os.path.normpath('mock_objects/test_users_associated')
    with open(response_file) as json_file:
        j_data = json.load(json_file)
    return j_data


class Test_StackAPI(unittest.TestCase):
    def test_no_site_provided(self):
        """Testing that it raises the correct error when no site is provided"""
        with self.assertRaises(ValueError) as cm:
            site = StackAPI()
            self.assertEqual('No Site Name provided', str(cm.exception))

    @patch('stackapi.StackAPI.fetch', fake_stackoverflow_exists)
    def test_stackoverflow_exists(self):
        """Simply testing the object is created correctly"""
        self.assertEqual(StackAPI('stackoverflow')._name, "Stack Overflow")
<commit_msg>Adjust tests to include the `tests/` directory based on current running location<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import os.path
import unittest
from mock import patch
from stackapi import StackAPI
from stackapi import StackAPIError

TESTS_DIRECTORY = "tests"
directory = "tests/" if TESTS_DIRECTORY not in os.getcwd() else ""

def fake_stackoverflow_exists(self, endpoint=None, page=1, key=None, filter='default', **kwargs):
    response_file = os.path.normpath('{}mock_objects/test_stackoverflow_exists'.format(directory))
    with open(response_file) as json_file:
        j_data = json.load(json_file)
    return j_data


def fake_users(self, endpoint=None, page=1, key=None, filter='default', **kwargs):
    response_file = os.path.normpath('{}mock_objects/test_users_associated'.format(directory))
    with open(response_file) as json_file:
        j_data = json.load(json_file)
    return j_data


class Test_StackAPI(unittest.TestCase):
    def test_no_site_provided(self):
        """Testing that it raises the correct error when no site is provided"""
        with self.assertRaises(ValueError) as cm:
            site = StackAPI()
            self.assertEqual('No Site Name provided', str(cm.exception))

    @patch('stackapi.StackAPI.fetch', fake_stackoverflow_exists)
    def test_stackoverflow_exists(self):
        """Simply testing the object is created correctly"""
        self.assertEqual(StackAPI('stackoverflow')._name, "Stack Overflow")

{'fraction_non_alphanumeric': 0.10693848354792561, 'fraction_numerical': 0.002145922746781116, 'mean_word_length': 4.35823754789272, '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': '734445', 'n_tokens_mistral': 827, 'n_tokens_neox': 813, 'n_words': 215}