コード例 #1
0
 def test_invalid_format(self):
     lang = languages.Languages()
     # Dict of strings instead of dict of dict
     conf1 = {'c': 'C'}
     # List instead of dict
     conf2 = [{
         'name': "C",
         'priority': 1,
         'files': "*.c",
         'compile':
         "/usr/bin/gcc -g -O2 -std=gnu99 -static -o {binary} {files} -lm",
         'run': "{binary}"
     }, {
         'name': "C++",
         'priority': 2,
         'files': "*.cc *.C *.cpp *.cxx *.c++",
         'compile':
         "/usr/bin/g++ -g -O2 -std=gnu++11 -static -o {binary} {files}",
         'run': "{binary}"
     }]
     conf3 = None
     with pytest.raises(languages.LanguageConfigError):
         lang.update(conf1)
     with pytest.raises(languages.LanguageConfigError):
         lang.update(conf2)
     with pytest.raises(languages.LanguageConfigError):
         lang.update(conf3)
コード例 #2
0
    def test_zoo(self):
        langs = languages.Languages()

        zoo = {'zoo': {'name': "Zoo",
                       'priority': 10,
                       'files': "*.zoo",
                       'run': "{binary}"},
               'zoork': {'name': "Zoork",
                         'priority': 20,
                         'files': "*.zoo",
                         'shebang': ">.*Zoork",
                         'run': "{binary}"},
               'zoopp': {'name': "Zoo++",
                         'priority': 0,
                         'files': "*.zoo *.zpp",
                         'run': "{binary}"}
               }

        langs.update(zoo)

        lang = langs.detect_language([examples_path(x) for x in ['src1.zoo']])
        assert lang.lang_id == 'zoo'

        lang = langs.detect_language([examples_path(x) for x in ['src2.zoo']])
        assert lang.lang_id == 'zoork'

        lang = langs.detect_language([examples_path(x) for x in ['src2.zoo', 'src3.zpp']])
        assert lang.lang_id == 'zoopp'
コード例 #3
0
 def test_invalid_format(self):
     lang = languages.Languages()
     with pytest.raises(languages.LanguageConfigError):
         lang.update(examples_path('invalid_format1.yaml'))
     with pytest.raises(languages.LanguageConfigError):
         lang.update(examples_path('invalid_format2.yaml'))
     with pytest.raises(languages.LanguageConfigError):
         lang.update(examples_path('invalid_format3.yaml'))
コード例 #4
0
    def test_zoo(self):
        langs = languages.Languages()
        langs.update(examples_path('zoo.yaml'))

        lang = langs.detect_language(
            map(lambda x: examples_path(x), ['src1.zoo']))
        assert lang.lang_id == 'zoo'

        lang = langs.detect_language(
            map(lambda x: examples_path(x), ['src2.zoo']))
        assert lang.lang_id == 'zoork'

        lang = langs.detect_language(
            map(lambda x: examples_path(x), ['src2.zoo', 'src3.zpp']))
        assert lang.lang_id == 'zoopp'
コード例 #5
0
    def test_duplicate_prio(self):
        lang = languages.Languages()
        config = {'c': {'name': "C",
                        'priority': 42,
                        'files': "*.c",
                        'compile': "/usr/bin/gcc -g -O2 -std=gnu99 -static -o {binary} {files} -lm",
                        'run': "{binary}"},
                  'cpp': {'name': "C++",
                          'priority': 42,
                          'files': "*.cc *.C *.cpp *.cxx *.c++",
                          'compile': "/usr/bin/g++ -g -O2 -std=gnu++11 -static -o {binary} {files}",
                          'run': "{binary}"}}

        with pytest.raises(languages.LanguageConfigError):
            lang.update(config)
コード例 #6
0
 def test_empty(self):
     lang = languages.Languages()
     lang.update({})
     assert lang.languages == {}
コード例 #7
0
 def test_empty_languages(self):
     lang = languages.Languages()
     assert lang.languages == {}
     assert lang.detect_language(['foo.cpp', 'foo.c', 'foo.py', 'foo.java'
                                  ]) is None
コード例 #8
0
 def test_duplicate_prio(self):
     lang = languages.Languages()
     with pytest.raises(languages.LanguageConfigError):
         lang.update(examples_path('duplicate_prios.yaml'))
コード例 #9
0
 def test_empty_file(self):
     lang = languages.Languages()
     lang.update(examples_path('emptyfile.yaml'))
     assert lang.languages == {}