示例#1
0
    def test_language(self):
        def _check_lang(sample):
            blob = self.blob(sample['path'])
            assert blob.language, 'No language for %s' % sample['path']
            assert sample['language'] == blob.language.name, blob.name

        Samples.each(_check_lang)
示例#2
0
    def test_language(self):
        def _check_lang(sample):
            blob = self.blob(sample['path'])
            assert blob.language, 'No language for %s' % sample['path']
            assert sample['language'] == blob.language.name, blob.name

        Samples.each(_check_lang)
示例#3
0
    def test_classify_ambiguous_languages(self):
        def classify_ambiguous_languages(sample):
            language = Language.find_by_name(sample['language'])
            languages = Language.find_by_filename(sample['path'])
            languages_names = [x.name for x in languages]

            results = Classifier.classify(DATA, open(sample['path']).read(), languages_names)

            self.assertEqual(language.name, results[0][0])

        samples = Samples()
        samples.generate()
        samples.each(classify_ambiguous_languages)
示例#4
0
    def test_find_by_shebang(self):
        assert 'ruby' == Samples.interpreter_from_shebang("#!/usr/bin/ruby\n# baz")

        for key, shebangs in self.SHEBANG_EXAMPLES.iteritems():
            for shebang in shebangs:
                language = Language.find_by_shebang(shebang)
                print Language[key], language
                if key is None:
                    self.assertEqual(Language[key], language)
                else:
                    self.assertTrue(Language[key] in language)