예제 #1
0
    def test_determine_changes(self):

        # Checks on the situation before first iteration:

        # manually written Org-mode file; has to be placed in
        # "../testdata/basic_blog_update_test/"
        template_file = "templates/blog-format.org"
        org_testfile_firstrun = "testdata/basic_blog_update_test/basic_blog_update_test_-_first_run.org"
        metadata_firstrun_output = "testdata/basic_blog_update_test/basic_blog_update_test_-_first_run.pk"
        metadata_secondrun_output = "testdata/basic_blog_update_test/basic_blog_update_test_-_second_run.pk"
        log_firstrun = "testdata/basic_blog_update_test/basic_blog_update_test_-_first_run.log"
        org_testfile_secondrun = "testdata/basic_blog_update_test/basic_blog_update_test_-_second_run.org"

        # might be left over from a failed previous run:
        if os.path.isfile(metadata_firstrun_output):
            os.remove(metadata_firstrun_output)

        # might be left over from a failed previous run:
        if os.path.isfile(log_firstrun):
            os.remove(log_firstrun)

        # check, if test input file is found
        self.assertTrue(os.path.isfile(template_file))
        # check, if test input file is found
        self.assertTrue(os.path.isfile(org_testfile_firstrun))
        # check, if test input file is found
        self.assertTrue(os.path.isfile(org_testfile_secondrun))

        # Building the call parameters:

        first_parser = argparse.ArgumentParser()
        first_parser.add_argument("--orgfiles", dest="orgfiles", nargs='+')
        first_parser.add_argument("--targetdir", dest="targetdir")
        first_parser.add_argument("--new-metadata",
                                  dest="new_metadatafilename")
        first_parser.add_argument("--previous-metadata",
                                  dest="previous_metadatafilename")
        first_parser.add_argument("--logfile", dest="logfilename")
        first_parser.add_argument("-v",
                                  "--verbose",
                                  dest="verbose",
                                  action="store_true")

        myoptions = "--orgfiles " + template_file + " " + org_testfile_firstrun + \
            " --targetdir ../testdata/basic_blog_update_test/2del-results/ --previous-metadata NOTEXISTING.pk --new-metadata " + \
            metadata_firstrun_output + \
            " --logfile " + log_firstrun  # + " --verbose"

        options = first_parser.parse_args(myoptions.split())

        # Invoking lazyblorg first interation:

        first_lazyblorg = Lazyblorg(options, self.logging)
        generate, marked_for_feed, increment_version, stats_parsed_org_files, stats_parsed_org_lines = first_lazyblorg.determine_changes(
        )

        # Checking results:

        generate_sorted = sorted(generate)
        marked_for_feed_sorted = sorted(marked_for_feed)
        # increment_version_sorted = sorted(increment_version)

        self.assertTrue(increment_version == [])
        self.assertTrue(generate_sorted == marked_for_feed_sorted)
        self.assertTrue(generate_sorted == [
            'case4', 'case5', 'case6', 'case7', 'case8',
            'empty-language-autotag-page', 'lazyblorg-templates'
        ])
        # Checks on the situation before second iteration:

        # none

        # Building the call parameters:

        second_parser = argparse.ArgumentParser()
        second_parser.add_argument("--orgfiles", dest="orgfiles", nargs='+')
        second_parser.add_argument("--targetdir", dest="targetdir")
        second_parser.add_argument("--new-metadata",
                                   dest="new_metadatafilename")
        second_parser.add_argument("--previous-metadata",
                                   dest="previous_metadatafilename")
        second_parser.add_argument("--logfile", dest="logfilename")
        second_parser.add_argument("-v",
                                   "--verbose",
                                   dest="verbose",
                                   action="store_true")

        myoptions = "--orgfiles " + org_testfile_secondrun + " " + template_file + \
            " --targetdir ../testdata/basic_blog_update_test/2del-results/ --previous-metadata " + \
            metadata_firstrun_output + \
            " --new-metadata " + metadata_secondrun_output + " --logfile " + log_firstrun  # + " --verbose"

        options = second_parser.parse_args(myoptions.split())

        # Invoking lazyblorg first interation:

        second_lazyblorg = Lazyblorg(options, self.logging)
        generate, marked_for_feed, increment_version, stats_parsed_org_files, stats_parsed_org_lines = second_lazyblorg.determine_changes(
        )

        # Checking results:

        generate_sorted = sorted(generate)
        marked_for_feed_sorted = sorted(marked_for_feed)
        increment_version_sorted = sorted(increment_version)

        self.assertTrue(increment_version_sorted == ['case8'])
        self.assertTrue(marked_for_feed_sorted == ['case1', 'case8'])
        self.assertTrue(generate_sorted == [
            'case1', 'case5', 'case6', 'case7', 'case8',
            'empty-language-autotag-page', 'lazyblorg-templates'
        ])

        if os.path.isfile(log_firstrun):
            os.remove(log_firstrun)

        os.remove(metadata_firstrun_output)
        os.remove(metadata_secondrun_output)

        return
예제 #2
0
    def test_example_entry_with_all_implemented_orgmode_elements(self):

        ## Checks on the situation before first iteration:

        ## manually written Org-mode file; has to be placed in "../testdata/basic_blog_update_test/"
        testname = "currently_supported_orgmode_syntax"
        template_file = "../templates/blog-format.org"
        org_testfile = "../testdata/" + testname + ".org"
        additional_org_file = "../testdata/about-placeholder.org"
        metadata_output = "../testdata/" + testname + ".pk"
        metadata_input = "../testdata/nonexisting.pk"
        log_firstrun = "../testdata/" + testname + ".log"
        target_dir = "../testdata/"

        ## might be left over from a failed previous run:
        if os.path.isfile(metadata_output):
            remove(metadata_output)

        ## might be left over from a failed previous run:
        if os.path.isfile(log_firstrun):
            remove(log_firstrun)

        self.assertTrue(os.path.isfile(template_file))  ## check, if test input file is found
        self.assertTrue(os.path.isfile(org_testfile))  ## check, if test input file is found
        self.assertTrue(os.path.isfile(additional_org_file))  ## check, if test input file is found
        
        ## Building the call parameters:
        first_parser = argparse.ArgumentParser()
        first_parser.add_argument("--orgfiles", dest="orgfiles", nargs='+')
        first_parser.add_argument("--targetdir", dest="targetdir")
        first_parser.add_argument("--new-metadata", dest="new_metadatafilename")
        first_parser.add_argument("--previous-metadata", dest="previous_metadatafilename")
        first_parser.add_argument("--logfile", dest="logfilename")
        first_parser.add_argument("-v", "--verbose", dest="verbose", action="store_true")

        myoptions = "--orgfiles " + org_testfile + " " + template_file + " " + additional_org_file + \
            " --targetdir " + target_dir + " --previous-metadata " + metadata_input + " --new-metadata " + \
            metadata_output + \
            " --logfile " + log_firstrun# + " --verbose"

        options = first_parser.parse_args(myoptions.split())

        ## Invoking lazyblorg first interation:

        mylazyblorg = Lazyblorg(options, self.logging)
        generate, marked_for_feed, increment_version, stats_parsed_org_files, stats_parsed_org_lines = mylazyblorg.determine_changes()

        ## Checking results:

        generate_sorted = sorted(generate)
        marked_for_feed_sorted = sorted(marked_for_feed)

        self.assertTrue(increment_version == [])
        self.assertTrue(generate_sorted == marked_for_feed_sorted)
        self.assertTrue(generate_sorted == [u'2014-01-27-full-syntax-test', u'2014-03-09-about', u'lazyblorg-templates'])

        blog_data, stats_parsed_org_lines = mylazyblorg._parse_orgmode_file(org_testfile)
        template_blog_data, template_stats_parsed_org_lines = mylazyblorg._parse_orgmode_file(template_file)
        additional_blog_data, additional_stats_parsed_org_lines = mylazyblorg._parse_orgmode_file(additional_org_file)
        blog_data += template_blog_data
        blog_data += additional_blog_data
        
        ## extract HTML templates and store in class var
        template_definitions = mylazyblorg._generate_template_definitions_from_template_data()

        htmlizer = Htmlizer(template_definitions, testname, "blog", "about this blog",
                            target_dir, blog_data, generate, increment_version)

        filename = htmlcontent = None
        for entry in blog_data:

            entry = htmlizer.sanitize_and_htmlize_blog_content(entry)

            if entry['category'] == config.TEMPORAL:
                filename, orgfilename, htmlcontent = htmlizer._generate_temporal_article(entry)
            elif entry['category'] == config.PERSISTENT:
                pass  ## FIXXME: probably add test for generating about-page as well

        htmloutputname = "../testdata/" + testname + ".html"
                
        ## generating HTML output in order to manually check in browser as well:
        with codecs.open(htmloutputname, 'wb', encoding='utf-8') as output:
            output.write(htmlcontent)

        self.assertTrue(os.path.isfile(htmloutputname))
            
        ## read in generated data from file:
        contentarray_from_file = []
        with codecs.open(htmloutputname, 'r', encoding='utf-8') as input:
            contentarray_from_file = input.readlines()

        ## read in comparson data from file:
        comparisonfilename = "../testdata/" + testname + "_COMPARISON.html"
        comparison_file_content = None
        with codecs.open(comparisonfilename, 'r', encoding='utf-8') as input:
            comparison_string_array = input.readlines()

        if len(comparison_string_array) != len(contentarray_from_file):
            print "length of produced data (" + str(len(contentarray_from_file)) + ") differs from comparison data (" + str(len(comparison_string_array)) + ")"
        
        ## a more fine-grained diff (only) on the first element in blog_data:
        for line in range(len(comparison_string_array)): 
            if contentarray_from_file[line].rstrip() != comparison_string_array[line].rstrip(): 
                print "=================  first difference  ===================== in line " + str(line)
                print "       [" + contentarray_from_file[line-1].rstrip() + "]"
                print "found  [" + contentarray_from_file[line].rstrip() + "]"
                print "       [" + contentarray_from_file[line+1].rstrip() + "]"
                print "    ---------------  comparison data:  --------------------"
                print "       [" + comparison_string_array[line-1].rstrip() + "]"
                print "should [" + comparison_string_array[line].rstrip() + "]"
                print "       [" + comparison_string_array[line+1].rstrip() + "]"
                print "=================                    ====================="
                self.assertTrue(contentarray_from_file[line].rstrip() == comparison_string_array[line].rstrip())
                    
        if os.path.isfile(metadata_output):
            remove(metadata_output)

        if os.path.isdir("../testdata/" + testname):
            import shutil
            shutil.rmtree("../testdata/" + testname)
예제 #3
0
    def test_determine_changes(self):

        # Checks on the situation before first iteration:

        # manually written Org-mode file; has to be placed in
        # "../testdata/basic_blog_update_test/"
        template_file = "templates/blog-format.org"
        org_testfile_firstrun = "testdata/basic_blog_update_test/basic_blog_update_test_-_first_run.org"
        metadata_firstrun_output = "testdata/basic_blog_update_test/basic_blog_update_test_-_first_run.pk"
        metadata_secondrun_output = "testdata/basic_blog_update_test/basic_blog_update_test_-_second_run.pk"
        log_firstrun = "testdata/basic_blog_update_test/basic_blog_update_test_-_first_run.log"
        org_testfile_secondrun = "testdata/basic_blog_update_test/basic_blog_update_test_-_second_run.org"

        # might be left over from a failed previous run:
        if os.path.isfile(metadata_firstrun_output):
            os.remove(metadata_firstrun_output)

        # might be left over from a failed previous run:
        if os.path.isfile(log_firstrun):
            os.remove(log_firstrun)

        # check, if test input file is found
        self.assertTrue(os.path.isfile(template_file))
        # check, if test input file is found
        self.assertTrue(os.path.isfile(org_testfile_firstrun))
        # check, if test input file is found
        self.assertTrue(os.path.isfile(org_testfile_secondrun))

        # Building the call parameters:

        first_parser = argparse.ArgumentParser()
        first_parser.add_argument("--orgfiles", dest="orgfiles", nargs='+')
        first_parser.add_argument("--targetdir", dest="targetdir")
        first_parser.add_argument(
            "--new-metadata",
            dest="new_metadatafilename")
        first_parser.add_argument(
            "--previous-metadata",
            dest="previous_metadatafilename")
        first_parser.add_argument("--logfile", dest="logfilename")
        first_parser.add_argument(
            "-v",
            "--verbose",
            dest="verbose",
            action="store_true")

        myoptions = "--orgfiles " + template_file + " " + org_testfile_firstrun + \
            " --targetdir ../testdata/basic_blog_update_test/2del-results/ --previous-metadata NOTEXISTING.pk --new-metadata " + \
            metadata_firstrun_output + \
            " --logfile " + log_firstrun  # + " --verbose"

        options = first_parser.parse_args(myoptions.split())

        # Invoking lazyblorg first interation:

        first_lazyblorg = Lazyblorg(options, self.logging)
        generate, marked_for_feed, increment_version, stats_parsed_org_files, stats_parsed_org_lines = first_lazyblorg.determine_changes()

        # Checking results:

        generate_sorted = sorted(generate)
        marked_for_feed_sorted = sorted(marked_for_feed)
        # increment_version_sorted = sorted(increment_version)

        self.assertTrue(increment_version == [])
        self.assertTrue(generate_sorted == marked_for_feed_sorted)
        self.assertTrue(
            generate_sorted == [
                'case4',
                'case5',
                'case6',
                'case7',
                'case8',
                'empty-autotag-page',
                'lazyblorg-templates'])
        # Checks on the situation before second iteration:

        # none

        # Building the call parameters:

        second_parser = argparse.ArgumentParser()
        second_parser.add_argument("--orgfiles", dest="orgfiles", nargs='+')
        second_parser.add_argument("--targetdir", dest="targetdir")
        second_parser.add_argument(
            "--new-metadata",
            dest="new_metadatafilename")
        second_parser.add_argument(
            "--previous-metadata",
            dest="previous_metadatafilename")
        second_parser.add_argument("--logfile", dest="logfilename")
        second_parser.add_argument(
            "-v",
            "--verbose",
            dest="verbose",
            action="store_true")

        myoptions = "--orgfiles " + org_testfile_secondrun + " " + template_file + \
            " --targetdir ../testdata/basic_blog_update_test/2del-results/ --previous-metadata " + \
            metadata_firstrun_output + \
            " --new-metadata " + metadata_secondrun_output + " --logfile " + log_firstrun  # + " --verbose"

        options = second_parser.parse_args(myoptions.split())

        # Invoking lazyblorg first interation:

        second_lazyblorg = Lazyblorg(options, self.logging)
        generate, marked_for_feed, increment_version, stats_parsed_org_files, stats_parsed_org_lines = second_lazyblorg.determine_changes()

        # Checking results:

        generate_sorted = sorted(generate)
        marked_for_feed_sorted = sorted(marked_for_feed)
        increment_version_sorted = sorted(increment_version)

        self.assertTrue(increment_version_sorted == ['case8'])
        self.assertTrue(marked_for_feed_sorted == ['case1', 'case8'])
        self.assertTrue(
            generate_sorted == [
                'case1',
                'case5',
                'case6',
                'case7',
                'case8',
                'empty-autotag-page',
                'lazyblorg-templates'])

        if os.path.isfile(log_firstrun):
            os.remove(log_firstrun)

        os.remove(metadata_firstrun_output)
        os.remove(metadata_secondrun_output)

        return
예제 #4
0
    def test_example_entry_with_all_implemented_orgmode_elements(self):

        ## Checks on the situation before first iteration:

        ## manually written Org-mode file; has to be placed in "../testdata/basic_blog_update_test/"
        testname = "currently_supported_orgmode_syntax"
        template_file = "../templates/blog-format.org"
        org_testfile = "../testdata/" + testname + ".org"
        additional_org_file = "../testdata/about-placeholder.org"
        metadata_output = "../testdata/" + testname + ".pk"
        metadata_input = "../testdata/nonexisting.pk"
        log_firstrun = "../testdata/" + testname + ".log"
        target_dir = "../testdata/"
        autotag_language = True

        ## might be left over from a failed previous run:
        if os.path.isfile(metadata_output):
            os.remove(metadata_output)

        ## might be left over from a failed previous run:
        if os.path.isfile(log_firstrun):
            os.remove(log_firstrun)

        self.assertTrue(os.path.isfile(
            template_file))  # check, if test input file is found
        self.assertTrue(
            os.path.isfile(org_testfile))  # check, if test input file is found
        self.assertTrue(os.path.isfile(
            additional_org_file))  # check, if test input file is found

        ## Building the call parameters:
        first_parser = argparse.ArgumentParser()
        first_parser.add_argument("--orgfiles", dest="orgfiles", nargs='+')
        first_parser.add_argument("--targetdir", dest="targetdir")
        first_parser.add_argument("--new-metadata",
                                  dest="new_metadatafilename")
        first_parser.add_argument("--previous-metadata",
                                  dest="previous_metadatafilename")
        first_parser.add_argument("--logfile", dest="logfilename")
        first_parser.add_argument("-v",
                                  "--verbose",
                                  dest="verbose",
                                  action="store_true")

        myoptions = "--orgfiles " + org_testfile + " " + template_file + " " + additional_org_file + \
            " --targetdir " + target_dir + " --previous-metadata " + metadata_input + " --new-metadata " + \
            metadata_output + \
            " --logfile " + log_firstrun  # + " --verbose"

        options = first_parser.parse_args(myoptions.split())

        ## Invoking lazyblorg first interation:

        mylazyblorg = Lazyblorg(options, self.logging)
        generate, marked_for_feed, increment_version, stats_parsed_org_files, stats_parsed_org_lines = mylazyblorg.determine_changes(
        )

        ## Checking results:

        generate_sorted = sorted(generate)
        marked_for_feed_sorted = sorted(marked_for_feed)

        self.assertTrue(increment_version == [])
        self.assertTrue(generate_sorted == marked_for_feed_sorted)
        self.assertTrue(generate_sorted == [
            u'2014-01-27-full-syntax-test', u'2014-03-09-about',
            u'lazyblorg-templates'
        ])

        blog_data, stats_parsed_org_lines = mylazyblorg._parse_orgmode_file(
            org_testfile)
        template_blog_data, template_stats_parsed_org_lines = mylazyblorg._parse_orgmode_file(
            template_file)
        additional_blog_data, additional_stats_parsed_org_lines = mylazyblorg._parse_orgmode_file(
            additional_org_file)
        blog_data += template_blog_data
        blog_data += additional_blog_data

        ## extract HTML templates and store in class var
        template_definitions = mylazyblorg._generate_template_definitions_from_template_data(
        )

        htmlizer = Htmlizer(template_definitions, testname, "blog",
                            "about this blog", target_dir, blog_data, generate,
                            increment_version, autotag_language)

        htmlcontent = None
        for entry in blog_data:

            entry = htmlizer.sanitize_and_htmlize_blog_content(entry)

            if entry['category'] == config.TEMPORAL:
                filename, orgfilename, htmlcontent = htmlizer._generate_temporal_article(
                    entry)
            elif entry['category'] == config.PERSISTENT:
                pass  # FIXXME: probably add test for generating about-page as well
            ## FIXXME: probably add test for generating tags-page as well

        htmloutputname = "../testdata/" + testname + ".html"

        ## generating HTML output in order to manually check in browser as well:
        with codecs.open(htmloutputname, 'wb', encoding='utf-8') as output:
            output.write(htmlcontent)

        self.assertTrue(os.path.isfile(htmloutputname))

        ## read in generated data from file:
        contentarray_from_file = []
        with codecs.open(htmloutputname, 'r', encoding='utf-8') as input:
            contentarray_from_file = input.readlines()

        ## read in comparson data from file:
        comparisonfilename = "../testdata/" + testname + "_COMPARISON.html"

        with codecs.open(comparisonfilename, 'r', encoding='utf-8') as input:
            comparison_string_array = input.readlines()

        if len(comparison_string_array) != len(contentarray_from_file):
            print "length of produced data (" + str(
                len(contentarray_from_file
                    )) + ") differs from comparison data (" + str(
                        len(comparison_string_array)) + ")"

        ## a more fine-grained diff (only) on the first element in blog_data:
        self.assertTrue(
            Utils.diff_two_lists(contentarray_from_file,
                                 comparison_string_array,
                                 normalize_lineendings=True))

        if os.path.isfile(metadata_output):
            os.remove(metadata_output)

        if os.path.isdir("../testdata/" + testname):
            import shutil
            shutil.rmtree("../testdata/" + testname)