<commit_before>package com.linkedin.gradle.python.extension

import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Specification


class PythonDetailsTest extends Specification {

    def project = new ProjectBuilder().build()
    def settings = new PythonDetails(project, null)

    def "interpreterPath without interpreterVersion"() {
        expect: "default system Python without any settings"
        settings.getSystemPythonInterpreter()
    }

    def "interpreterPath with interpreterVersion"() {
        when: "we request 2.7"
        settings.pythonVersion = '2.7'
        then: "we get 2.7"
        settings.getSystemPythonInterpreter().path.endsWith("2.7")
    }

    def "interpreterPath with unsupported interpreterVersion"() {
        when: "we request an unsupported version"
        settings.pythonVersion = '2.5'
        then: "we throw an exception"
        thrown(RuntimeException)
    }

    def "interpreterPath with unsupported major only interpreterVersion"() {
        when: "we request an unsupported major only version"
        settings.pythonVersion = '1'
        then: "we throw an exception"
        thrown(RuntimeException)
    }

    def "interpreterPath with major only 2 interpreterVersion"() {
        when: "we request only the major version 2"
        settings.pythonVersion= '2'
        then: "we get the default major version 2 cleanpython or the system default if cleanptyhon is not installed"
        settings.getSystemPythonInterpreter().path.endsWith("2.6")
    }

    def "interpreterPath with major only 3 interpreterVersion"() {
        when: "we request only the major version 3"
        settings.pythonVersion = '3'
        then: "we get the default major version 3 cleanpython or the system default if cleanpython is not installed"
        settings.getSystemPythonInterpreter().path.endsWith("3.5")
    }

    def "interpreterPath with systemPython set"() {
        when: "we have old systemPython setting"
        settings.pythonVersion = '2.6'
        settings.systemPythonInterpreter = '/usr/bin/python2.7'
        then: "we get that as interpreter path"
        settings.systemPythonInterpreter.absolutePath == '/usr/bin/python2.7'
    }

    def "interpreterPath with nonsense interpreterVersion"() {
        when: "we request a nonsense version and try to get the interpreter path"
        settings.pythonVersion = 'x.y'
        then: "the exception is thrown"
        thrown(RuntimeException)
    }
}<commit_msg>Make it so that the test will pass on machines w/o 2.7<commit_after>package com.linkedin.gradle.python.extension

import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Requires
import spock.lang.Specification


class PythonDetailsTest extends Specification {

    def project = new ProjectBuilder().build()
    def settings = new PythonDetails(project, null)

    def "interpreterPath without interpreterVersion"() {
        expect: "default system Python without any settings"
        settings.getSystemPythonInterpreter()
    }

    def "interpreterPath with interpreterVersion"() {
        when: "we request 2.7"
        settings.pythonVersion = '2.7'
        then: "we get 2.7"
        settings.getSystemPythonInterpreter().path.endsWith("2.7")
    }

    def "interpreterPath with unsupported interpreterVersion"() {
        when: "we request an unsupported version"
        settings.pythonVersion = '2.5'
        then: "we throw an exception"
        thrown(RuntimeException)
    }

    def "interpreterPath with unsupported major only interpreterVersion"() {
        when: "we request an unsupported major only version"
        settings.pythonVersion = '1'
        then: "we throw an exception"
        thrown(RuntimeException)
    }

    def "interpreterPath with major only 2 interpreterVersion"() {
        when: "we request only the major version 2"
        settings.pythonVersion= '2'
        then: "we get the default major version 2 cleanpython or the system default if cleanptyhon is not installed"
        settings.getSystemPythonInterpreter().path.endsWith("2.6")
    }

    def "interpreterPath with major only 3 interpreterVersion"() {
        when: "we request only the major version 3"
        settings.pythonVersion = '3'
        then: "we get the default major version 3 cleanpython or the system default if cleanpython is not installed"
        settings.getSystemPythonInterpreter().path.endsWith("3.5")
    }

    @Requires({ new File('/usr/bin/python2.7').exists() })
    def "interpreterPath with systemPython set"() {
        when: "we have old systemPython setting"
        settings.pythonVersion = '2.6'
        settings.systemPythonInterpreter = '/usr/bin/python2.7'
        then: "we get that as interpreter path"
        settings.systemPythonInterpreter.absolutePath == '/usr/bin/python2.7'
    }

    def "interpreterPath with nonsense interpreterVersion"() {
        when: "we request a nonsense version and try to get the interpreter path"
        settings.pythonVersion = 'x.y'
        then: "the exception is thrown"
        thrown(RuntimeException)
    }
}
{'fraction_non_alphanumeric': 0.08577611646665355, 'fraction_numerical': 0.012197521148927798, 'mean_word_length': 3.0253365003958828, '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': '6894267', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1342, 'n_words': 436}