Пример #1
0
    def test_unexistent_template_name(self):
        """Reference implementation should match mustache and mako implem"""

        w("""cat <<EOF > .gitchangelog.rc

output_engine = mustache('doesnotexist')

EOF
        """)
        out, err, errlvl = cmd('$tprog')
        self.assertEqual(
            errlvl, 1,
            msg="Should fail as template does not exist")
        self.assertEqual(
            out, "",
            msg="No stdout was expected since there was an error. "
            "Current stdout:\n%r" % out)
        self.assertContains(
            err, "doesnotexist",
            msg="There should be an error message mentioning 'doesnotexist'. "
            "Current stderr:\n%s" % err)
        self.assertContains(
            err, "restructuredtext",
            msg="The error message should mention 'available'. "
            "Current stderr:\n%s" % err)
        self.assertContains(
            err, "mustache",
            msg="The error message should mention 'mustache'. "
            "Current stderr:\n%s" % err)
        self.assertContains(
            err, "restructuredtext",
            msg="The error message should mention 'restructuredtext'. "
            "Current stderr:\n%s" % err)
Пример #2
0
 def test_simple_run(self):
     out, err, errlvl = cmd('$tprog')
     self.assertEqual(
         errlvl, 0,
         msg="Should not fail on simple repo and without config file")
     self.assertEqual(
         err, "",
         msg="There should be no standard error outputed. "
         "Current stderr:\n%r" % err)
     self.assert_contains(
         out, "0.0.2",
         msg="At least one of the tags should be displayed in stdout... "
         "Current stdout:\n%s" % out)
Пример #3
0
    def test_outside_git_repository(self):

        out, err, errlvl = cmd('$tprog init')
        self.assertEqual(
            errlvl, 1,
            msg="Should fail to init outside a git repository.")
        self.assertContains(
            err, "repository",
            msg="There should be a error msg mentioning 'repository'. "
            "Current stderr:\n%r" % err)
        self.assertEqual(
            out, "",
            msg="No standard output message expected. "
            "Current stdout:\n%s" % out)
Пример #4
0
    def test_init_file_already_exists(self):

        w("touch .gitchangelog.rc")
        out, err, errlvl = cmd('$tprog init')
        self.assertEqual(
            errlvl, 1,
            msg="Should fail to init on simple git repository")
        self.assertContains(
            err, "exists",
            msg="There should be a error msg mentioning the file exists. "
            "Current stderr:\n%r" % err)
        self.assertEqual(
            out, "",
            msg="No standard output message expected in case of error "
            "Current stdout:\n%s" % out)
Пример #5
0
 def test_config_file_is_not_a_file(self):
     w("""
         mkdir .gitchangelog.rc
     """)
     out, err, errlvl = cmd('$tprog')
     self.assertEqual(
         errlvl, 1,
         msg="Should fail when bogus config file exists but is not a file")
     self.assertContains(
         err, "not a file",
         msg="There should be a error message stating that config file is not a file."
         "Current stderr:\n%r" % err)
     self.assertEqual(
         out, "",
         msg="There should be no standard output. "
         "Current stdout:\n%s" % out)
Пример #6
0
    def test_init_file(self):

        out, err, errlvl = cmd('$tprog init')
        self.assertEqual(
            errlvl, 0,
            msg="Should not fail to init on simple git repository")
        self.assertEqual(
            err, "",
            msg="There should be no standard error outputed. "
            "Current stdout:\n%r" % out)
        self.assertContains(
            out, "created",
            msg="Output message should mention that the file was created... "
            "Current stdout:\n%s" % out)
        self.assertTrue(
            os.path.exists('.gitchangelog.rc'),
            msg="File must have been created.")
Пример #7
0
    def test_in_bare_repository(self):
        w("""

            cd ..
            git clone --bare repos test_bare

        """)
        out, err, errlvl = cmd('cd ../test_bare && $tprog init')
        self.assertEqual(
            errlvl, 1,
            msg="Should fail to init outside a git repository.")
        self.assertContains(
            err, "bare",
            msg="There should be a error msg mentioning 'bare'. "
            "Current stderr:\n%r" % err)
        self.assertEqual(
            out, "",
            msg="No standard output message expected. "
            "Current stdout:\n%s" % out)
Пример #8
0
 def test_simple_run_show_call(self):
     out, err, errlvl = cmd('$tprog show')
     self.assertEqual(
         errlvl, 0,
         msg="Should not fail on simple repo and without config file")
     self.assertEqual(
         err, "",
         msg="There should be no standard error outputed. "
         "Current stderr:\n%r" % err)
     self.assertContains(
         out, "0.0.2",
         msg="At least one of the tags should be displayed in stdout... "
         "Current stdout:\n%s" % out)
     self.assertEqual(
         out, self.REFERENCE,
         msg="Should match our reference output... "
         "diff of changelogs:\n%s"
         % '\n'.join(difflib.unified_diff(out.split("\n"),
                                          self.REFERENCE.split("\n"),
                                          lineterm="")))
Пример #9
0
    def test_in_sub_repository(self):
        w("""

            mkdir subdir
            cd subdir

        """)
        out, err, errlvl = cmd('$tprog init')
        self.assertEqual(errlvl, 0, msg="Should not fail in sub directory.")
        self.assertContains(
            out,
            "created",
            msg="There should be a msg mentioning the file was 'created'. "
            "Current stdout:\n%r" % out)
        self.assertEqual(err,
                         "",
                         msg="No error message expected. "
                         "Current stderr:\n%s" % err)
        self.assertTrue(os.path.exists('.gitchangelog.rc'),
                        msg="File must have been created.")
Пример #10
0
    def test_in_bare_repository(self):
        w("""

            cd ..
            git clone --bare repos test_bare

        """)
        out, err, errlvl = cmd('cd ../test_bare && $tprog init')
        self.assertEqual(errlvl,
                         1,
                         msg="Should fail to init outside a git repository.")
        self.assertContains(
            err,
            "bare",
            msg="There should be a error msg mentioning 'bare'. "
            "Current stderr:\n%r" % err)
        self.assertEqual(out,
                         "",
                         msg="No standard output message expected. "
                         "Current stdout:\n%s" % out)
Пример #11
0
    def test_with_filename_same_as_tag(self):
        w("""

            touch 0.0.1

        """)
        out, err, errlvl = cmd('$tprog')
        self.assertEqual(
            errlvl, 0,
            msg="Should not fail even if filename same as tag name.")
        self.assertEqual(
            err, "",
            msg="No error message expected. "
            "Current stderr:\n%s" % err)
        self.assertEqual(
            out, self.REFERENCE,
            msg="Should match our reference output... "
            "diff of changelogs:\n%s"
            % '\n'.join(difflib.unified_diff(out.split("\n"),
                                             self.REFERENCE.split("\n"),
                                             lineterm="")))
Пример #12
0
    def test_provided_config_file(self):
        """Check provided reference with older name for perfect same result."""

        config_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                  "..")
        configs = glob.glob(
            os.path.join(config_dir, "gitchangelog.rc.reference.v*"))
        for config in configs:
            out, err, errlvl = cmd('GITCHANGELOG_CONFIG_FILENAME="%s" $tprog' %
                                   config)
            self.assertEqual(errlvl,
                             0,
                             msg="Should not fail with config %r " %
                             (config, ) + "Current stderr:\n%s" % indent(err))
            self.assertEqual(
                out,
                self.REFERENCE,
                msg="Mako output should match our reference output... "
                "diff of changelogs:\n%s" % '\n'.join(
                    difflib.unified_diff(self.REFERENCE.split("\n"),
                                         out.split("\n"),
                                         lineterm="")))
Пример #13
0
 def test_simple_run(self):
     out, err, errlvl = cmd('$tprog')
     self.assertEqual(
         errlvl,
         0,
         msg="Should not fail on simple repo and without config file")
     self.assertEqual(err,
                      "",
                      msg="There should be no standard error outputed. "
                      "Current stderr:\n%r" % err)
     self.assertContains(
         out,
         "0.0.2",
         msg="At least one of the tags should be displayed in stdout... "
         "Current stdout:\n%s" % out)
     self.assertEqual(
         out,
         self.REFERENCE,
         msg="Should match our reference output... "
         "diff of changelogs:\n%s" % '\n'.join(
             difflib.unified_diff(
                 out.split("\n"), self.REFERENCE.split("\n"), lineterm="")))
Пример #14
0
    def test_in_sub_repository(self):
        w("""

            mkdir subdir
            cd subdir

        """)
        out, err, errlvl = cmd('$tprog init')
        self.assertEqual(
            errlvl, 0,
            msg="Should not fail in sub directory.")
        self.assertContains(
            out, "created",
            msg="There should be a msg mentioning the file was 'created'. "
            "Current stdout:\n%r" % out)
        self.assertEqual(
            err, "",
            msg="No error message expected. "
            "Current stderr:\n%s" % err)
        self.assertTrue(
            os.path.exists('.gitchangelog.rc'),
            msg="File must have been created.")
Пример #15
0
    def test_with_filename_same_as_tag(self):
        w("""

            touch 0.0.1

        """)
        out, err, errlvl = cmd('$tprog')
        self.assertEqual(
            errlvl,
            0,
            msg="Should not fail even if filename same as tag name.")
        self.assertEqual(err,
                         "",
                         msg="No error message expected. "
                         "Current stderr:\n%s" % err)
        self.assertEqual(
            out,
            self.REFERENCE,
            msg="Should match our reference output... "
            "diff of changelogs:\n%s" % '\n'.join(
                difflib.unified_diff(
                    out.split("\n"), self.REFERENCE.split("\n"), lineterm="")))
Пример #16
0
    def test_provided_config_file(self):
        """Check provided reference with older name for perfect same result."""

        config_dir = os.path.join(
            os.path.dirname(os.path.realpath(__file__)), "..")
        configs = glob.glob(os.path.join(config_dir,
                                         "gitchangelog.rc.reference.v*"))
        for config in configs:
            out, err, errlvl = cmd(
                'GITCHANGELOG_CONFIG_FILENAME="%s" $tprog' % config)
            self.assertEqual(
                errlvl, 0,
                msg="Should not fail with config %r " % (config, ) +
                "Current stderr:\n%s" % indent(err))
            self.assertEqual(
                out, self.REFERENCE,
                msg="Mako output should match our reference output... "
                "diff of changelogs:\n%s"
                % '\n'.join(difflib.unified_diff(
                    self.REFERENCE.split("\n"),
                    out.split("\n"),
                    lineterm="")))
Пример #17
0
 def test_incremental_show_call(self):
     out, err, errlvl = cmd('$tprog show 0.0.2..0.0.3')
     self.assertEqual(
         errlvl,
         0,
         msg="Should not fail on simple repo and without config file")
     self.assertEqual(err,
                      "",
                      msg="There should be no standard error outputed. "
                      "Current stderr:\n%r" % err)
     self.assertContains(
         out,
         "0.0.3",
         msg="The tag 0.0.3 should be displayed in stdout... "
         "Current stdout:\n%s" % out)
     self.assertEqual(
         out,
         self.INCR_REFERENCE_002_003,
         msg="Should match our reference output... "
         "diff of changelogs:\n%s" % '\n'.join(
             difflib.unified_diff(out.split("\n"),
                                  self.INCR_REFERENCE_002_003.split("\n"),
                                  lineterm="")))
Пример #18
0
    def test_provided_templates(self):
        """Run all provided templates at least once"""

        for label, directory in [("makotemplate", "mako"),
                                 ("mustache", "mustache")]:
            template_dir = os.path.join(
                os.path.dirname(os.path.realpath(__file__)),
                "..", "templates", directory)
            templates = glob.glob(os.path.join(template_dir, "*.tpl"))
            template_labels = [os.path.basename(f).split(".")[0]
                               for f in templates]
            for tpl in template_labels:
                w("""cat <<EOF > .gitchangelog.rc

output_engine = %s(%r)

EOF
                """ % (label, tpl))
                out, err, errlvl = cmd('$tprog')
                self.assertEqual(
                    errlvl, 0,
                    msg="Should not fail on %s(%r) " % (label, tpl) +
                    "Current stderr:\n%s" % indent(err))
Пример #19
0
    def test_unexistent_template_name(self):
        """Reference implementation should match mustache and mako implem"""

        w("""cat <<EOF > .gitchangelog.rc

output_engine = mustache('doesnotexist')

EOF
        """)
        out, err, errlvl = cmd('$tprog')
        self.assertEqual(errlvl,
                         1,
                         msg="Should fail as template does not exist")
        self.assertEqual(
            out,
            "",
            msg="No stdout was expected since there was an error. "
            "Current stdout:\n%r" % out)
        self.assertContains(
            err,
            "doesnotexist",
            msg="There should be an error message mentioning 'doesnotexist'. "
            "Current stderr:\n%s" % err)
        self.assertContains(
            err,
            "restructuredtext",
            msg="The error message should mention 'available'. "
            "Current stderr:\n%s" % err)
        self.assertContains(err,
                            "mustache",
                            msg="The error message should mention 'mustache'. "
                            "Current stderr:\n%s" % err)
        self.assertContains(
            err,
            "restructuredtext",
            msg="The error message should mention 'restructuredtext'. "
            "Current stderr:\n%s" % err)
Пример #20
0
logger.debug('RGB_AVG #' + rgb_avg)

darkness = 2.0
rgb_dark = '%02X%02X%02X' % (ravg/darkness, gavg/darkness, bavg/darkness)
logger.debug('RGB_DARK ' + rgb_dark)

lightness = 2.0
rgb_light = '%02X%02X%02X' % (255-int((255-ravg)/lightness), 255-int((255-gavg)/lightness), 255-int((255-bavg)/lightness))
logger.debug('RGB_LIGHT ' + rgb_light)


# create coin graphic
icon_width = 150
file_logo_resized = '/tmp/passport-resized-icon-{}.png'.format(os.getpid())
dimensions = '{}x{}!'.format(icon_width, icon_width)
cmd(['convert', file_icon, '-resize', dimensions, file_logo_resized])


# add coin graphic to background
position = '+55+15'
cmd(['composite', '-geometry', position, file_logo_resized, file_background, file_output])
os.remove(file_logo_resized)


# add currency symbol header
size = str(240 - (36 * len(symbol)))
position = '+230+{}'.format(210 - (20 * len(symbol)))
font = 'DejaVu-Sans-Bold'
cmd(['convert', file_output, '-font', font, '-fill', '#{}'.format(rgb_avg), '-pointsize', size, '-annotate', position, symbol, file_output])