<commit_before>import os
import tempfile
import shutil

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

from django.test import LiveServerTestCase
from django.test.utils import override_settings
from django.conf import settings

from instances.tests import InstanceLiveServerTestCase

import speeches
from speeches.models import Speaker, Speech

@override_settings(MEDIA_ROOT=tempfile.mkdtemp())
class SeleniumTests(InstanceLiveServerTestCase):
    @classmethod
    def setUpClass(cls):
        cls.selenium = webdriver.Firefox()
        cls._in_fixtures = os.path.join(os.path.abspath(speeches.__path__[0]), 'fixtures', 'test_inputs')
        super(SeleniumTests, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        cls.selenium.quit()
        super(SeleniumTests, cls).tearDownClass()

    def tearDown(self):
        # Clear the speeches folder if it exists
        speeches_folder = os.path.join(settings.MEDIA_ROOT, 'speeches')
        if(os.path.exists(speeches_folder)):
            shutil.rmtree(speeches_folder)

    @property
    def live_server_url(self):
        url = super(SeleniumTests, self).live_server_url
        return url.replace('localhost', 'testing.127.0.0.1.xip.io')

    def test_select_text_and_audio(self):
        self.selenium.get('%s%s' % (self.live_server_url, '/speech/add'))

        # Assert form is shown with audio input and text input
        self.assertTrue(self.selenium.find_element_by_id("speech-form").is_displayed())
        self.assertTrue(self.selenium.find_element_by_id("id_audio_controls").is_displayed())
        self.assertTrue(self.selenium.find_element_by_id("id_text_controls").is_displayed())

    def test_add_speech(self):
        self.selenium.get('%s%s' % (self.live_server_url, '/speech/add'))<commit_msg>Don't run selenium tests unless explicitly asked.<commit_after>import os
import tempfile
import shutil

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

from django.test import LiveServerTestCase
from django.test.utils import override_settings
from django.utils import unittest
from django.conf import settings

from instances.tests import InstanceLiveServerTestCase

import speeches
from speeches.models import Speaker, Speech

skip_selenium = not os.environ.get('SELENIUM_TESTS', False)

@unittest.skipIf(skip_selenium, 'Selenium tests not requested')
@override_settings(MEDIA_ROOT=tempfile.mkdtemp())
class SeleniumTests(InstanceLiveServerTestCase):
    @classmethod
    def setUpClass(cls):
        if getattr(cls, "__unittest_skip__", False):
            return
        cls.selenium = webdriver.Firefox()
        cls._in_fixtures = os.path.join(os.path.abspath(speeches.__path__[0]), 'fixtures', 'test_inputs')
        super(SeleniumTests, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        if getattr(cls, "__unittest_skip__", False):
            return
        cls.selenium.quit()
        super(SeleniumTests, cls).tearDownClass()

    def tearDown(self):
        # Clear the speeches folder if it exists
        speeches_folder = os.path.join(settings.MEDIA_ROOT, 'speeches')
        if(os.path.exists(speeches_folder)):
            shutil.rmtree(speeches_folder)

    @property
    def live_server_url(self):
        url = super(SeleniumTests, self).live_server_url
        return url.replace('localhost', 'testing.127.0.0.1.xip.io')

    def test_select_text_and_audio(self):
        self.selenium.get('%s%s' % (self.live_server_url, '/speech/add'))

        # Assert form is shown with audio input and text input
        self.assertTrue(self.selenium.find_element_by_id("speech-form").is_displayed())
        self.assertTrue(self.selenium.find_element_by_id("id_audio_controls").is_displayed())
        self.assertTrue(self.selenium.find_element_by_id("id_text_controls").is_displayed())

    def test_add_speech(self):
        self.selenium.get('%s%s' % (self.live_server_url, '/speech/add'))
{'fraction_non_alphanumeric': 0.10579092504387065, 'fraction_numerical': 0.0035096515417397845, 'mean_word_length': 4.057034220532319, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2741560', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1225, 'n_words': 234}