<commit_before>import json
import os
import unittest

from reqhash import parser

class RequirementsParserTest(unittest.TestCase):

    fixture_path =  os.path.join(os.path.dirname(os.path.realpath(__file__)), 'fixtures')

    def test_normalize(self):
        reqs_path = self.get_fixture('simple')
        reqs_w_comments_path = self.get_fixture('simple_w_comments')
        with file(reqs_path) as reqs:
            with file(reqs_w_comments_path) as reqs_w_comments:
                normalized = parser.normalize_reqs(reqs)
                normalized_w_comments = parser.normalize_reqs(reqs_w_comments)
                self.assertEqual(normalized, normalized_w_comments)

    def test_parse_simple(self):
        reqs_path, expected = self.get_testset('simple')
        reqs = parser.parse_requirements(reqs_path)
        self.assertEquals(reqs, expected)

    def test_parse_nested(self):
        reqs_path, expected = self.get_testset('nested')
        reqs = parser.parse_requirements(reqs_path)
        self.assertEquals(reqs, expected)

    def test_normalize_inline(self):
        reqs_path = self.get_fixture('simple')
        reqs_w_inline_comments_path = self.get_fixture('simple_w_inline_comments')
        with file(reqs_path) as reqs, file(reqs_w_inline_comments_path) as reqs_w_inline_comments:
            normalized = parser.normalize_reqs(reqs)
            normalized_w_inline_comments = parser.normalize_reqs(reqs_w_inline_comments)
            self.assertEqual(normalized, normalized_w_inline_comments)

    def get_fixture(self, name):
        return os.path.join(self.fixture_path, name + '.txt')

    def get_testset(self, name):
        basename = os.path.join(self.fixture_path, name)
        reqs_path = self.get_fixture(name)
        expected_path = basename + '.json'
        with file(expected_path) as expected_file:
            expected = json.load(expected_file)
        return reqs_path, expected

<commit_msg>Fixed tests for Python 2.6<commit_after>import json
import os
import unittest

from reqhash import parser

class RequirementsParserTest(unittest.TestCase):

    fixture_path =  os.path.join(os.path.dirname(os.path.realpath(__file__)), 'fixtures')

    def test_normalize(self):
        reqs_path = self.get_fixture('simple')
        reqs_w_comments_path = self.get_fixture('simple_w_comments')
        with file(reqs_path) as reqs:
            with file(reqs_w_comments_path) as reqs_w_comments:
                normalized = parser.normalize_reqs(reqs)
                normalized_w_comments = parser.normalize_reqs(reqs_w_comments)
                self.assertEqual(normalized, normalized_w_comments)

    def test_parse_simple(self):
        reqs_path, expected = self.get_testset('simple')
        reqs = parser.parse_requirements(reqs_path)
        self.assertEquals(reqs, expected)

    def test_parse_nested(self):
        reqs_path, expected = self.get_testset('nested')
        reqs = parser.parse_requirements(reqs_path)
        self.assertEquals(reqs, expected)

    def test_normalize_inline(self):
        reqs_path = self.get_fixture('simple')
        reqs_w_inline_comments_path = self.get_fixture('simple_w_inline_comments')
        with file(reqs_path) as reqs:
            with file(reqs_w_inline_comments_path) as reqs_w_inline_comments:
                normalized = parser.normalize_reqs(reqs)
                normalized_w_inline_comments = parser.normalize_reqs(reqs_w_inline_comments)
                self.assertEqual(normalized, normalized_w_inline_comments)

    def get_fixture(self, name):
        return os.path.join(self.fixture_path, name + '.txt')

    def get_testset(self, name):
        basename = os.path.join(self.fixture_path, name)
        reqs_path = self.get_fixture(name)
        expected_path = basename + '.json'
        with file(expected_path) as expected_file:
            expected = json.load(expected_file)
        return reqs_path, expected


{'fraction_non_alphanumeric': 0.08519837232960326, 'fraction_numerical': 0.000508646998982706, 'mean_word_length': 3.2983606557377048, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2380488', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1228, 'n_words': 203}