def test_bootstrapCarriesOutAsExpected(self):
        config = TestConfig()
        ProgrammingParser.bootstrap(config)
        self.bootstrapMock.assert_called_with(config)

        self.assertEqual(486, len(registry.get('PP_all_keywords')))
        self.assertEqual(11, len(registry.get('PP_language_keywords')))
    def test_parse(self):
        '''tests parse with a small spread in bayesian match values'''
        config = TestConfig()
        ProgrammingParser.bootstrap(config)
        self.bootstrapMock.assert_called_with(config)

        parser = ProgrammingParser(config)

        expected_types = [
            'Visual Basic',
            'Python',
            'PHP'
        ]

        results = []

        for result in parser.parse('with cout echo'):
            self.assertIsInstance(result, ParseResult)
            results.append(result)

        self.assertEqual(3, len(results))

        for result in results:
            self.assertIn(result.subtype, expected_types)

        self.smallSpreadClassifyMock.assert_called_once_with('with cout echo')
Beispiel #3
0
    def test_parseWithLargeDeepNegativeSpread(self):
        '''tests parse with a large spread in bayesian match values'''
        config = TestConfig()
        ProgrammingParser.bootstrap(config)
        self.bootstrapMock.assert_called_with(config)

        parser = ProgrammingParser(config)

        expected_types = (
            'Visual Basic',
            'JavaScript',
            'ActionScript',
            'Python',
            'PHP'
        )

        results = []

        for result in parser.parse('with cout echo'):
            self.assertIsInstance(result, ParseResult)
            results.append(result)

        self.assertEqual(5, len(results))

        for result in results:
            self.assertIn(result.subtype, expected_types)

        self.bigSpreadClassifyMock.assert_called_once_with('with cout echo')
    def test_find_common_tokensFindsExpectedKeywords(self):
        config = TestConfig()
        ProgrammingParser.bootstrap(config)
        self.bootstrapMock.assert_called_with(config)

        parser = ProgrammingParser(config)
        result = parser.find_common_tokens(['for', 'if', 'foobar'])

        self.assertEqual(2, len(result))
    def test_parseWithNoLexedLanguagesReturns(self):
        config = TestConfig()
        ProgrammingParser.bootstrap(config)
        self.bootstrapMock.assert_called_with(config)

        parser = ProgrammingParser(config)
        count = 0
        for _ in parser.parse('m foo bar'):
            count += 1
        self.assertEqual(0, count)
    def test_parseWithNoCommonTokensReturns(self):
        config = TestConfig()
        ProgrammingParser.bootstrap(config)
        self.bootstrapMock.assert_called_with(config)

        parser = ProgrammingParser(config)
        count = 0
        for _ in parser.parse('scoobydoo'):
            count += 1
        self.assertEqual(0, count)
    def test_basicLanguageHeuristicFindsExpectedKeywords(self):
        config = TestConfig()
        ProgrammingParser.bootstrap(config)
        self.bootstrapMock.assert_called_with(config)

        parser = ProgrammingParser(config)
        result = parser.basic_language_heuristic(
            registry.get('PP_language_keywords')['php'],
            ['for', 'if', 'foobar']
        )

        self.assertEqual(2, len(result))