
from runner.koan import *


class AboutDecoratingWithFunctions(Koan):
    def addcowbell(fn):
        fn.wow_factor = 'COWBELL BABY!'
        return fn

    @addcowbell
    def mediocre_song(self):
        return "o/~ We all live in a broken submarine o/~"

    def test_decorators_can_modify_a_function(self):
        self.assertRegex(self.mediocre_song(), __)
        self.assertEqual(__, self.mediocre_song.wow_factor)

    # ------------------------------------------------------------------

    def xmltag(fn):
        def func(*args):
            return '<' + fn(*args) + '/>'
        return func

    @xmltag
    def render_tag(self, name):
        return name

    def test_decorators_can_change_a_function_output(self):
        self.assertEqual(__, self.render_tag('llama'))


from runner.koan import *


class AboutDecoratingWithFunctions(Koan):
    def addcowbell(fn):
        fn.wow_factor = 'COWBELL BABY!'
        return fn

    @addcowbell
    def mediocre_song(self):
        return "o/~ We all live in a broken submarine o/~"

    def test_decorators_can_modify_a_function(self):
        self.assertRegex(self.mediocre_song(), "o/~ We all live in a broken submarine o/~")
        self.assertEqual("COWBELL BABY!", self.mediocre_song.wow_factor)

    # ------------------------------------------------------------------

    def xmltag(fn):
        def func(*args):
            return '<' + fn(*args) + '/>'
        return func

    @xmltag
    def render_tag(self, name):
        return name

    def test_decorators_can_change_a_function_output(self):
        self.assertEqual("<llama/>", self.render_tag('llama'))

Complete 'About Decorating with functions' koans
[Python] Complete 'About Decorating with functions' koans

  
  from runner.koan import *
  
  
  class AboutDecoratingWithFunctions(Koan):
      def addcowbell(fn):
          fn.wow_factor = 'COWBELL BABY!'
          return fn
  
      @addcowbell
      def mediocre_song(self):
          return "o/~ We all live in a broken submarine o/~"
  
      def test_decorators_can_modify_a_function(self):
-         self.assertRegex(self.mediocre_song(), __)
+         self.assertRegex(self.mediocre_song(), "o/~ We all live in a broken submarine o/~")
-         self.assertEqual(__, self.mediocre_song.wow_factor)
+         self.assertEqual("COWBELL BABY!", self.mediocre_song.wow_factor)
  
      # ------------------------------------------------------------------
  
      def xmltag(fn):
          def func(*args):
              return '<' + fn(*args) + '/>'
          return func
  
      @xmltag
      def render_tag(self, name):
          return name
  
      def test_decorators_can_change_a_function_output(self):
-         self.assertEqual(__, self.render_tag('llama'))
+         self.assertEqual("<llama/>", self.render_tag('llama'))
  
Complete 'About Decorating with functions' koans
## Code Before:

from runner.koan import *


class AboutDecoratingWithFunctions(Koan):
    def addcowbell(fn):
        fn.wow_factor = 'COWBELL BABY!'
        return fn

    @addcowbell
    def mediocre_song(self):
        return "o/~ We all live in a broken submarine o/~"

    def test_decorators_can_modify_a_function(self):
        self.assertRegex(self.mediocre_song(), __)
        self.assertEqual(__, self.mediocre_song.wow_factor)

    # ------------------------------------------------------------------

    def xmltag(fn):
        def func(*args):
            return '<' + fn(*args) + '/>'
        return func

    @xmltag
    def render_tag(self, name):
        return name

    def test_decorators_can_change_a_function_output(self):
        self.assertEqual(__, self.render_tag('llama'))

## Instruction:
Complete 'About Decorating with functions' koans
## Code After:

from runner.koan import *


class AboutDecoratingWithFunctions(Koan):
    def addcowbell(fn):
        fn.wow_factor = 'COWBELL BABY!'
        return fn

    @addcowbell
    def mediocre_song(self):
        return "o/~ We all live in a broken submarine o/~"

    def test_decorators_can_modify_a_function(self):
        self.assertRegex(self.mediocre_song(), "o/~ We all live in a broken submarine o/~")
        self.assertEqual("COWBELL BABY!", self.mediocre_song.wow_factor)

    # ------------------------------------------------------------------

    def xmltag(fn):
        def func(*args):
            return '<' + fn(*args) + '/>'
        return func

    @xmltag
    def render_tag(self, name):
        return name

    def test_decorators_can_change_a_function_output(self):
        self.assertEqual("<llama/>", self.render_tag('llama'))
