def test_json_output_from_multiple_files(self):
        for test_files in _TEST_MULTI_FILES:
            # Get old JSON example test output
            expected_json = _slurp_file(_TEST_ROOT,
                "-".join(test_files) + '.json')

            # Generate new output to check
            output = extract_strings.extract_files(
                [os.path.join(_EXERCISE_ROOT, test_file + '.html')
                    for test_file in test_files])
            output = json.dumps(output, cls=extract_strings._SetEncoder)

            self.assertEqual(output, expected_json, test_files)
    def test_json_output_from_all_files(self):
        # Generate new output to check
        output = extract_strings.extract_files(
            glob.glob(os.path.join(_EXERCISE_ROOT, '*.html')))

        # Make sure that we don't cause something bad to happen
        # and no longer output drastically less results.
        # As of 2013-01-23 we have 4776 results.
        self.assertGreater(len(output), 4500, 'Too few strings extracted.')

        for string in output:
            # Make sure that no <div> are found in the extracted string
            self.assertNotRegexpMatches(string, r'<div',
                'DIV element found in %s' % list(output[string])[0][0])

            # Make sure that no <p> are found in the extracted string
            self.assertNotRegexpMatches(string, r'<p',
                'P element found in %s' % list(output[string])[0][0])
    def test_json_output_from_multiple_files(self):
        for test_files in _TEST_MULTI_FILES:
            # Get old JSON example test output
            raw_expected_output = _load_test_json("-".join(test_files))

            # The python output uses both tuples and lists, while the
            # json has only lists (it doesn't support tuples).
            # Convert the json so all the types match.
            expected_output = []
            for (nltext, occurrences) in raw_expected_output:
                # nltext can be a string (for gettext) or a list (ngettext)
                if isinstance(nltext, list):
                    nltext = tuple(nltext)     # we want a tuple, not a list
                converted_occs = [(str(f), lnum) for (f, lnum) in occurrences]
                expected_output.append((nltext, converted_occs))

            # Generate new output to check
            output = extract_strings.extract_files(
                [os.path.join(_TEST_ROOT, test_file + '.html')
                    for test_file in test_files],
                verbose=False)

            self.assertEqual(output, expected_output)
    def test_json_output_from_all_files(self):
        # Generate new output to check
        output = extract_strings.extract_files(
            glob.glob(os.path.join(_EXERCISE_ROOT, '*.html')),
            verbose=False)

        # Make sure that we don't cause something bad to happen
        # and no longer output drastically less results.
        # As of 2013-01-23 we have 4776 results.
        self.assertGreater(len(output), 4500, 'Too few strings extracted.')

        for (nltext, occurrences) in output:
            # nltext can be either a string (for gettext) or tuple (ngettext)
            if isinstance(nltext, basestring):
                nltext = (nltext,)   # make it so nltext is definitely a tuple
            for string in nltext:
                # Make sure that no <div> are found in the extracted string
                self.assertNotRegexpMatches(string, r'<div',
                    'DIV element found at %s:%s' % occurrences[0])

                # Make sure that no <p> are found in the extracted string
                self.assertNotRegexpMatches(string, r'<p',
                    'P element found at %s:%s' % occurrences[0])
    def test_json_output_from_multiple_files(self):
        for test_files in _TEST_MULTI_FILES:
            # Get old JSON example test output
            raw_expected_output = _load_test_json("-".join(test_files))

            # The python output uses both tuples and lists, while the
            # json has only lists (it doesn't support tuples).
            # Convert the json so all the types match.
            expected_output = []
            for (nltext, occurrences) in raw_expected_output:
                # nltext can be a string (for gettext) or a list (ngettext)
                if isinstance(nltext, list):
                    nltext = tuple(nltext)  # we want a tuple, not a list
                converted_occs = [(str(f), lnum) for (f, lnum) in occurrences]
                expected_output.append((nltext, converted_occs))

            # Generate new output to check
            output = extract_strings.extract_files([
                os.path.join(_TEST_ROOT, test_file + '.html')
                for test_file in test_files
            ],
                                                   verbose=False)

            self.assertEqual(output, expected_output)
    def test_json_output_from_all_files(self):
        # Generate new output to check
        output = extract_strings.extract_files(glob.glob(
            os.path.join(_EXERCISE_ROOT, '*.html')),
                                               verbose=False)

        # Make sure that we don't cause something bad to happen
        # and no longer output drastically less results.
        # As of 2013-01-23 we have 4776 results.
        self.assertGreater(len(output), 4500, 'Too few strings extracted.')

        for (nltext, occurrences) in output:
            # nltext can be either a string (for gettext) or tuple (ngettext)
            if isinstance(nltext, basestring):
                nltext = (nltext, )  # make it so nltext is definitely a tuple
            for string in nltext:
                # Make sure that no <div> are found in the extracted string
                self.assertNotRegexpMatches(
                    string, r'<div',
                    'DIV element found at %s:%s' % occurrences[0])

                # Make sure that no <p> are found in the extracted string
                self.assertNotRegexpMatches(
                    string, r'<p', 'P element found at %s:%s' % occurrences[0])