コード例 #1
0
    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')))
コード例 #2
0
    def test_calculate_confidence(self):
        lex_languages = {
            'foo': 12
        }
        bayes_languages = {
            'foo': 150
        }

        pp = ProgrammingParser(TestConfig())

        result = \
            pp.calculate_confidence(
                lex_languages,
                bayes_languages
            )

        self.assertEqual({
            'foo': {
                'confidence': 100,
                'scores': {
                    'bayes': 99.92,
                    'final': 100.0,
                    'lexer': 0.08
                }
            }
        }, result)
コード例 #3
0
    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')
コード例 #4
0
ファイル: __init__.py プロジェクト: msabramo/cahoots
    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')
コード例 #5
0
    def test_createDatasetReturnsExpectedList(self):
        config = TestConfig()
        parser = ProgrammingParser(config)

        self.assertEqual(
            set(['hello', 'world']),
            parser.create_dataset('Hello World')
        )
コード例 #6
0
    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))
コード例 #7
0
    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)
コード例 #8
0
    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)
コード例 #9
0
    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))