<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
import shutil
import requests
from splash.tests import ts
from splash.tests.utils import TestServers, SplashServer
from splash.tests.test_render import BaseRenderTest


class BaseFiltersTest(BaseRenderTest):
    def assertFiltersWork(self, resp, noscript, noscript2):
        """
        Check that filters work. There are two testing filters
        (see splash/tests/filters), "noscript" that filters script.js,
        and "noscript2" that filters script2.js.

        ``resp`` must be a response returned by a request to 'iframes'
        endpoint of mock server. ``noscript`` and ``noscript2`` are boolean
        variables.
        """
        if noscript:
            self.assertNotIn('SAME_DOMAIN', resp.text)
        else:
            self.assertIn('SAME_DOMAIN', resp.text)

        if noscript2:
            self.assertNotIn('OTHER_DOMAIN', resp.text)
        else:
            self.assertIn('OTHER_DOMAIN', resp.text)

    def params(self, **kwargs):
        kwargs.setdefault('url', ts.mockserver.url('iframes'))
        return kwargs


class FiltersTestHTML(BaseFiltersTest):

    def test_filtering_work(self):
        r = self.request(self.params())
        self.assertFiltersWork(r, noscript=False, noscript2=False)

        r = self.request(self.params(filters='noscript'))
        self.assertFiltersWork(r, noscript=True, noscript2=False)

        r = self.request(self.params(filters='noscript2'))
        self.assertFiltersWork(r, noscript=False, noscript2=True)

    def test_multiple_filters(self):
        r = self.request(self.params(filters='noscript,noscript2'))
        self.assertFiltersWork(r, noscript=True, noscript2=True)

    def test_invalid_filters(self):
        r = self.request(self.params(filters='foo,noscript2'))
        self.assertEqual(r.status_code, 400)
        self.assertIn('foo', r.text)


class DefaultFiltersTest(BaseFiltersTest):<commit_msg>TST make use of "mockurl" method in request filters test<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import
import os
import shutil
import requests
from splash.tests.utils import TestServers, SplashServer
from splash.tests.test_render import BaseRenderTest


class BaseFiltersTest(BaseRenderTest):
    def assertFiltersWork(self, resp, noscript, noscript2):
        """
        Check that filters work. There are two testing filters
        (see splash/tests/filters), "noscript" that filters script.js,
        and "noscript2" that filters script2.js.

        ``resp`` must be a response returned by a request to 'iframes'
        endpoint of mock server. ``noscript`` and ``noscript2`` are boolean
        variables.
        """
        if noscript:
            self.assertNotIn('SAME_DOMAIN', resp.text)
        else:
            self.assertIn('SAME_DOMAIN', resp.text)

        if noscript2:
            self.assertNotIn('OTHER_DOMAIN', resp.text)
        else:
            self.assertIn('OTHER_DOMAIN', resp.text)

    def params(self, **kwargs):
        kwargs.setdefault('url', self.mockurl('iframes'))
        return kwargs


class FiltersTestHTML(BaseFiltersTest):

    def test_filtering_work(self):
        r = self.request(self.params())
        self.assertFiltersWork(r, noscript=False, noscript2=False)

        r = self.request(self.params(filters='noscript'))
        self.assertFiltersWork(r, noscript=True, noscript2=False)

        r = self.request(self.params(filters='noscript2'))
        self.assertFiltersWork(r, noscript=False, noscript2=True)

    def test_multiple_filters(self):
        r = self.request(self.params(filters='noscript,noscript2'))
        self.assertFiltersWork(r, noscript=True, noscript2=True)

    def test_invalid_filters(self):
        r = self.request(self.params(filters='foo,noscript2'))
        self.assertEqual(r.status_code, 400)
        self.assertIn('foo', r.text)


class DefaultFiltersTest(BaseFiltersTest):
{'fraction_non_alphanumeric': 0.10926485397784491, 'fraction_numerical': 0.008056394763343404, 'mean_word_length': 3.226595744680851, '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': '2539620', 'n_tokens_mistral': 1188, 'n_tokens_neox': 1171, 'n_words': 266}