Ejemplo n.º 1
0
    def test_atcoder_4_fsharp(self):
        languages = languages_atcoder_4
        filename = 'Main.fs'
        code = 'open System\nprintfn "Hello, world!"\n'
        expected = [
            Language(id=LanguageId('4022'), name='F# (.NET Core 3.1.201)'),
            Language(id=LanguageId('4023'), name='F# (Mono 10.2.3)')
        ]

        self.assertEqual(
            language_gussing.guess_languages_of_file(
                filename=pathlib.Path(filename),
                code=code.encode(),
                languages=languages), expected)
Ejemplo n.º 2
0
    def test_codeforces_haskell(self):
        languages = languages_codeforces
        filename = 'Main.hs'
        code = 'main = return ()\n'
        expected = [Language(id=LanguageId('12'), name='Haskell GHC 8.6.3')]

        self.assertEqual(
            language_gussing.guess_languages_of_file(
                filename=pathlib.Path(filename),
                code=code.encode(),
                languages=languages), expected)
Ejemplo n.º 3
0
    def test_atcoder_3_rust(self):
        languages = languages_atcoder_3
        filename = 'main.rs'
        code = 'fn main() { println!("Hello, world!"); }\n'
        expected = [Language(id=LanguageId('3504'), name='Rust (1.15.1)')]

        self.assertEqual(
            language_gussing.guess_languages_of_file(
                filename=pathlib.Path(filename),
                code=code.encode(),
                languages=languages), expected)
Ejemplo n.º 4
0
    def test_codeforces_pypy_3(self):
        languages = languages_codeforces
        filename = 'main.py'
        code = 'print("hello")\n'
        python_version = 'auto'
        python_interpreter = 'pypy'
        expected = [Language(id=LanguageId('41'), name='PyPy 3.6 (7.2.0)')]

        self.assertEqual(
            language_gussing.guess_languages_of_file(
                filename=pathlib.Path(filename),
                code=code.encode(),
                languages=languages,
                python_version=python_version,
                python_interpreter=python_interpreter), expected)
Ejemplo n.º 5
0
    def test_atcoder_4_python_3(self):
        languages = languages_atcoder_4
        filename = 'main.py'
        code = 'print("hello")\n'
        python_version = 'auto'
        python_interpreter = 'cpython'
        expected = [Language(id=LanguageId('4006'), name='Python (3.8.2)')]

        self.assertEqual(
            language_gussing.guess_languages_of_file(
                filename=pathlib.Path(filename),
                code=code.encode(),
                languages=languages,
                python_version=python_version,
                python_interpreter=python_interpreter), expected)
Ejemplo n.º 6
0
    def test_atcoder_4_clang(self):
        languages = languages_atcoder_4
        filename = 'main.cpp'
        code = 'int main() {}\n'
        cxx_latest = True
        cxx_compiler = 'clang'
        expected = [Language(id=LanguageId('4004'), name='C++ (Clang 10.0.0)')]

        self.assertEqual(
            language_gussing.guess_languages_of_file(
                filename=pathlib.Path(filename),
                code=code.encode(),
                languages=languages,
                cxx_latest=cxx_latest,
                cxx_compiler=cxx_compiler), expected)
Ejemplo n.º 7
0
    def test_atcoder_3_gcc(self):
        languages = languages_atcoder_3
        filename = 'main.cpp'
        code = 'int main() {}\n'
        cxx_latest = True
        cxx_compiler = 'gcc'
        expected = [Language(id=LanguageId('3003'), name='C++14 (GCC 5.4.1)')]

        self.assertEqual(
            language_gussing.guess_languages_of_file(
                filename=pathlib.Path(filename),
                code=code.encode(),
                languages=languages,
                cxx_latest=cxx_latest,
                cxx_compiler=cxx_compiler), expected)
Ejemplo n.º 8
0
    def test_codeforces_clang(self):
        languages = languages_codeforces
        filename = 'main.cpp'
        code = 'int main() {}\n'
        cxx_latest = True
        cxx_compiler = 'clang'
        expected = [
            Language(id=LanguageId('52'), name='Clang++17 Diagnostics')
        ]

        self.assertEqual(
            language_gussing.guess_languages_of_file(
                filename=pathlib.Path(filename),
                code=code.encode(),
                languages=languages,
                cxx_latest=cxx_latest,
                cxx_compiler=cxx_compiler), expected)
Ejemplo n.º 9
0
    def test_codeforces_pypy_2(self):
        languages = languages_codeforces
        filename = 'main.py'
        code = textwrap.dedent("""\
            #!/usr/bin/env python2
            print("hello")
            """)
        python_version = 'auto'
        python_interpreter = 'pypy'
        expected = [Language(id=LanguageId('40'), name='PyPy 2.7 (7.2.0)')]

        self.assertEqual(
            language_gussing.guess_languages_of_file(
                filename=pathlib.Path(filename),
                code=code.encode(),
                languages=languages,
                python_version=python_version,
                python_interpreter=python_interpreter), expected)
Ejemplo n.º 10
0
    def test_atcoder_3_python_2(self):
        languages = languages_atcoder_3
        filename = 'main.py'
        code = textwrap.dedent("""\
            #!/usr/bin/env python2
            print("hello")
            """)
        python_version = 'auto'
        python_interpreter = 'cpython'
        expected = [Language(id=LanguageId('3022'), name='Python2 (2.7.6)')]

        self.assertEqual(
            language_gussing.guess_languages_of_file(
                filename=pathlib.Path(filename),
                code=code.encode(),
                languages=languages,
                python_version=python_version,
                python_interpreter=python_interpreter), expected)
Ejemplo n.º 11
0
    def test_codeforces_gcc(self):
        languages = languages_codeforces
        filename = 'main.cpp'
        code = 'int main() {}\n'
        cxx_latest = True
        cxx_compiler = 'gcc'
        expected = [
            Language(id=LanguageId('61'),
                     name='GNU G++17 9.2.0 (64 bit, msys 2)')
        ]

        self.assertEqual(
            language_gussing.guess_languages_of_file(
                filename=pathlib.Path(filename),
                code=code.encode(),
                languages=languages,
                cxx_latest=cxx_latest,
                cxx_compiler=cxx_compiler), expected)
Ejemplo n.º 12
0
def guess_languages_of_file(filename: pathlib.Path,
                            code: bytes,
                            languages: List[Language],
                            *,
                            cxx_latest: bool = False,
                            cxx_compiler: str = 'all',
                            python_version: str = 'all',
                            python_interpreter: str = 'all') -> List[Language]:
    language_dict = {str(language.id): language.name for language in languages}
    language_ids = guess_language_ids_of_file(
        filename,
        code,
        language_dict=language_dict,
        cxx_latest=cxx_latest,
        cxx_compiler=cxx_compiler,
        python_version=python_version,
        python_interpreter=python_interpreter)
    return [
        Language(LanguageId(language_id), language_dict[language_id])
        for language_id in language_ids
    ]
Ejemplo n.º 13
0
import pathlib
import textwrap
import unittest

import onlinejudge._implementation.command.submit as submit
from onlinejudge.type import Language, LanguageId

# https://atcoder.jp/contests/language-test-ver1
languages_atcoder_3 = [
    Language(id=LanguageId('3001'), name='Bash (GNU bash v4.3.11)'),
    Language(id=LanguageId('3002'), name='C (GCC 5.4.1)'),
    Language(id=LanguageId('3003'), name='C++14 (GCC 5.4.1)'),
    Language(id=LanguageId('3004'), name='C (Clang 3.8.0)'),
    Language(id=LanguageId('3005'), name='C++14 (Clang 3.8.0)'),
    Language(id=LanguageId('3006'), name='C# (Mono 4.6.2.0)'),
    Language(id=LanguageId('3007'), name='Clojure (1.8.0)'),
    Language(id=LanguageId('3008'), name='Common Lisp (SBCL 1.1.14)'),
    Language(id=LanguageId('3009'), name='D (DMD64 v2.070.1)'),
    Language(id=LanguageId('3010'), name='D (LDC 0.17.0)'),
    Language(id=LanguageId('3011'), name='D (GDC 4.9.4)'),
    Language(id=LanguageId('3012'), name='Fortran (gfortran v4.8.4)'),
    Language(id=LanguageId('3013'), name='Go (1.6)'),
    Language(id=LanguageId('3014'), name='Haskell (GHC 7.10.3)'),
    Language(id=LanguageId('3015'), name='Java7 (OpenJDK 1.7.0)'),
    Language(id=LanguageId('3016'), name='Java8 (OpenJDK 1.8.0)'),
    Language(id=LanguageId('3017'), name='JavaScript (node.js v5.12)'),
    Language(id=LanguageId('3018'), name='OCaml (4.02.3)'),
    Language(id=LanguageId('3019'), name='Pascal (FPC 2.6.2)'),
    Language(id=LanguageId('3020'), name='Perl (v5.18.2)'),
    Language(id=LanguageId('3021'), name='PHP (5.6.30)'),
    Language(id=LanguageId('3022'), name='Python2 (2.7.6)'),