<commit_before># Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

import pytest

from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import UnexpectedTagNameException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

disabledSelect = {"name": "no-select", "values": ["Foo"]}
disabledSingleSelect = {"name": "single_disabled", "values": ["Enabled", "Disabled"]}
disabledMultiSelect = {"name": "multi_disabled", "values": ["Enabled", "Disabled"]}
singleSelectValues1 = {
    "name": "selectomatic",
    "values": ["One", "Two", "Four", "Still learning how to count, apparently"],
}
singleSelectValues2 = {"name": "redirect", "values": ["One", "Two"]}
singleSelectValuesWithSpaces = {
    "name": "select_with_spaces",
    "values": ["One", "Two", "Four", "Still learning how to count, apparently"],
}
multiSelectValues1 = {"name": "multi", "values": ["Eggs", "Ham", "Sausages", "Onion gravy"]}
multiSelectValues2 = {"name": "select_empty_multiple", "values": ["select_1", "select_2", "select_3", "select_4"]}


def test_select_by_index_single(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select["name"]))
        for x in range(len(select["values"])):
            sel.select_by_index(x)
            assert sel.first_selected_option.text == select["values"][x]


def test_raises_exception_select_by_index_single_disabled(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSingleSelect["name"]))
    with pytest.raises(NotImplementedError):
        sel.select_by_index(1)


@pytest.mark.xfail_firefox(reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1429403')
@pytest.mark.xfail_remote
def test_select_disabled_by_index(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSelect["name"]))
    selected = sel.first_selected_option
    sel.select_by_index(1)
    assert selected == sel.first_selected_option


def test_select_by_value_single(driver, pages):
    pages.load("formPage.html")
    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select["name"]))
        for x in range(len(select["values"])):
            sel.select_by_value(select["values"][x].lower())
            assert sel.first_selected_option.text == select["values"][x]


def test_raises_exception_select_by_value_single_disabled(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSingleSelect["name"]))
    with pytest.raises(NotImplementedError):
        sel.select_by_value(disabledSingleSelect["values"][1].lower())


@pytest.mark.xfail_firefox(reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1429403')
@pytest.mark.xfail_remote
def test_select_disabled_by_value(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSelect["name"]))
    selected = sel.first_selected_option
    sel.select_by_value("bar")
    assert selected == sel.first_selected_option


def test_select_by_visible_text_single(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select["name"]))
        for x in range(len(select["values"])):
            print(select["values"][x])
            sel.select_by_visible_text(select["values"][x])
            assert sel.first_selected_option.text == select["values"][x]


def test_raises_exception_select_by_text_single_disabled(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSingleSelect["name"]))
    with pytest.raises(NotImplementedError):
        sel.select_by_visible_text(disabledSingleSelect["values"][1])


@pytest.mark.xfail_firefox(reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1429403')
@pytest.mark.xfail_remote
def test_select_disabled_by_visible_text(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSelect["name"]))
    selected = sel.first_selected_option
    sel.select_by_visible_text("Bar")
    assert selected == sel.first_selected_option


def test_select_by_index_multiple(driver, pages):
    pages.load("formPage.html")

    for select in [multiSelectValues1, multiSelectValues2]:
        sel = Select(driver.find_element(By.NAME, select["name"]))
        sel.deselect_all()
        for x in range(len(select["values"])):
            sel.select_by_index(x)
            selected = sel.all_selected_options
            assert len(selected) == x + 1
            for j in range(len(selected)):
                assert selected[j].text == select["values"][j]


def test_raises_exception_select_by_index_multiple_disabled(driver, pages):
    pages.load("formPage.html")

    sel = Select(driver.find_element(By.NAME, disabledMultiSelect["name"]))
    with pytest.raises(NotImplementedError):<commit_msg>[py] still cannot select disabled options with Select class<commit_after># Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

import pytest

from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import UnexpectedTagNameException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

disabledSelect = {"name": "no-select", "values": ["Foo"]}
disabledSingleSelect = {"name": "single_disabled", "values": ["Enabled", "Disabled"]}
disabledMultiSelect = {"name": "multi_disabled", "values": ["Enabled", "Disabled"]}
singleSelectValues1 = {
    "name": "selectomatic",
    "values": ["One", "Two", "Four", "Still learning how to count, apparently"],
}
singleSelectValues2 = {"name": "redirect", "values": ["One", "Two"]}
singleSelectValuesWithSpaces = {
    "name": "select_with_spaces",
    "values": ["One", "Two", "Four", "Still learning how to count, apparently"],
}
multiSelectValues1 = {"name": "multi", "values": ["Eggs", "Ham", "Sausages", "Onion gravy"]}
multiSelectValues2 = {"name": "select_empty_multiple", "values": ["select_1", "select_2", "select_3", "select_4"]}


def test_select_by_index_single(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select["name"]))
        for x in range(len(select["values"])):
            sel.select_by_index(x)
            assert sel.first_selected_option.text == select["values"][x]


def test_raises_exception_select_by_index_single_disabled(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSingleSelect["name"]))
    with pytest.raises(NotImplementedError):
        sel.select_by_index(1)


def test_select_by_value_single(driver, pages):
    pages.load("formPage.html")
    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select["name"]))
        for x in range(len(select["values"])):
            sel.select_by_value(select["values"][x].lower())
            assert sel.first_selected_option.text == select["values"][x]


def test_raises_exception_select_by_value_single_disabled(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSingleSelect["name"]))
    with pytest.raises(NotImplementedError):
        sel.select_by_value(disabledSingleSelect["values"][1].lower())


def test_select_by_visible_text_single(driver, pages):
    pages.load("formPage.html")

    for select in [singleSelectValues1]:
        sel = Select(driver.find_element(By.NAME, select["name"]))
        for x in range(len(select["values"])):
            print(select["values"][x])
            sel.select_by_visible_text(select["values"][x])
            assert sel.first_selected_option.text == select["values"][x]


def test_raises_exception_select_by_text_single_disabled(driver, pages):
    pages.load("formPage.html")
    sel = Select(driver.find_element(By.NAME, disabledSingleSelect["name"]))
    with pytest.raises(NotImplementedError):
        sel.select_by_visible_text(disabledSingleSelect["values"][1])


def test_select_by_index_multiple(driver, pages):
    pages.load("formPage.html")

    for select in [multiSelectValues1, multiSelectValues2]:
        sel = Select(driver.find_element(By.NAME, select["name"]))
        sel.deselect_all()
        for x in range(len(select["values"])):
            sel.select_by_index(x)
            selected = sel.all_selected_options
            assert len(selected) == x + 1
            for j in range(len(selected)):
                assert selected[j].text == select["values"][j]


def test_raises_exception_select_by_index_multiple_disabled(driver, pages):
    pages.load("formPage.html")

    sel = Select(driver.find_element(By.NAME, disabledMultiSelect["name"]))
    with pytest.raises(NotImplementedError):
{'fraction_non_alphanumeric': 0.12862910978657952, 'fraction_numerical': 0.006152662949432801, 'mean_word_length': 4.753871681415929, 'pattern_counts': {'":': 32, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 2, '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': '412793', 'n_tokens_mistral': 3165, 'n_tokens_neox': 3093, 'n_words': 703}