# Path: lighthouse/haproxy/stanzas/stanza.py
# class Stanza(object):
#     """
#     Subclass for config file stanzas.
# 
#     In an HAProxy config file, a stanza is in the form of::
# 
#       stanza header
#           directive
#           directive
#           directive
# 
#     Stanza instances have a `header` attribute for the header and a list of
#     `lines`, one for each directive line.
#     """
# 
#     def __init__(self, section_name):
#         self.section_name = section_name
#         self.header = section_name
#         self.lines = []
# 
#     def add_lines(self, lines):
#         """
#         Simple helper method for adding multiple lines at once.
#         """
#         for line in lines:
#             self.add_line(line)
# 
#     def add_line(self, line):
#         """
#         Adds a given line string to the list of lines, validating the line
#         first.
#         """
#         if not self.is_valid_line(line):
#             logger.warn(
#                 "Invalid line for %s section: '%s'",
#                 self.section_name, line
#             )
#             return
# 
#         self.lines.append(line)
# 
#     def is_valid_line(self, line):
#         """
#         Validates a given line against the associated "section" (e.g. 'global'
#         or 'frontend', etc.) of a stanza.
# 
#         If a line represents a directive that shouldn't be within the stanza
#         it is rejected.  See the `directives.json` file for a condensed look
#         at valid directives based on section.
#         """
#         adjusted_line = line.strip().lower()
# 
#         return any([
#             adjusted_line.startswith(directive)
#             for directive in directives_by_section[self.section_name]
#         ])
# 
#     def __str__(self):
#         """
#         Returns the string representation of a Stanza, meant for use in
#         config file content.
# 
#         if no lines are defined an empty string is returned.
#         """
#         if not self.lines:
#             return ""
# 
#         return self.header + "\n" + "\n".join([
#             "\t" + line
#             for line in self.lines
#         ])
# 
# Path: lighthouse/haproxy/stanzas/section.py
# class Section(object):
#     """
#     Represents a section of HAProxy config file stanzas.
# 
#     This is used to organize generated config file content and provide header
#     comments for sections describing nature of the grouped-together stanzas.
#     """
# 
#     def __init__(self, heading, *stanzas):
#         self.heading = heading
#         self.stanzas = stanzas
#         if not self.stanzas:
#             self.stanzas = []
# 
#     @property
#     def header(self):
#         return "\n".join([
#             "#",
#             "# %s" % self.heading,
#             "#"
#         ])
# 
#     def __str__(self):
#         """
#         Joins together the section header and stanza strings with space
#         inbetween.
#         """
#         stanzas = list(self.stanzas)
#         if not stanzas:
#             stanzas = ["# No stanzas defined for this section."]
# 
#         return "\n\n".join(map(str, [self.header] + stanzas))


    import unittest2 as unittest
    import unittest
from lighthouse.haproxy.stanzas.stanza import Stanza
from lighthouse.haproxy.stanzas.section import Section
try:
except ImportError:



class SectionTests(unittest.TestCase):

    def test_no_stanzas(self):
        section = Section("A Section")

        self.assertTrue(
            "# No stanzas defined for this section." in str(section)
        )

    def test_heading(self):
        section = Section("This is a section, ok")

        self.assertTrue(
            str(section).startswith(
                "#\n" +
                "# This is a section, ok\n" +
                "#\n" +
                "\n"
            )
        )

    def test_stanzas(self):

# Path: lighthouse/haproxy/stanzas/stanza.py
# class Stanza(object):
#     """
#     Subclass for config file stanzas.
# 
#     In an HAProxy config file, a stanza is in the form of::
# 
#       stanza header
#           directive
#           directive
#           directive
# 
#     Stanza instances have a `header` attribute for the header and a list of
#     `lines`, one for each directive line.
#     """
# 
#     def __init__(self, section_name):
#         self.section_name = section_name
#         self.header = section_name
#         self.lines = []
# 
#     def add_lines(self, lines):
#         """
#         Simple helper method for adding multiple lines at once.
#         """
#         for line in lines:
#             self.add_line(line)
# 
#     def add_line(self, line):
#         """
#         Adds a given line string to the list of lines, validating the line
#         first.
#         """
#         if not self.is_valid_line(line):
#             logger.warn(
#                 "Invalid line for %s section: '%s'",
#                 self.section_name, line
#             )
#             return
# 
#         self.lines.append(line)
# 
#     def is_valid_line(self, line):
#         """
#         Validates a given line against the associated "section" (e.g. 'global'
#         or 'frontend', etc.) of a stanza.
# 
#         If a line represents a directive that shouldn't be within the stanza
#         it is rejected.  See the `directives.json` file for a condensed look
#         at valid directives based on section.
#         """
#         adjusted_line = line.strip().lower()
# 
#         return any([
#             adjusted_line.startswith(directive)
#             for directive in directives_by_section[self.section_name]
#         ])
# 
#     def __str__(self):
#         """
#         Returns the string representation of a Stanza, meant for use in
#         config file content.
# 
#         if no lines are defined an empty string is returned.
#         """
#         if not self.lines:
#             return ""
# 
#         return self.header + "\n" + "\n".join([
#             "\t" + line
#             for line in self.lines
#         ])
# 
# Path: lighthouse/haproxy/stanzas/section.py
# class Section(object):
#     """
#     Represents a section of HAProxy config file stanzas.
# 
#     This is used to organize generated config file content and provide header
#     comments for sections describing nature of the grouped-together stanzas.
#     """
# 
#     def __init__(self, heading, *stanzas):
#         self.heading = heading
#         self.stanzas = stanzas
#         if not self.stanzas:
#             self.stanzas = []
# 
#     @property
#     def header(self):
#         return "\n".join([
#             "#",
#             "# %s" % self.heading,
#             "#"
#         ])
# 
#     def __str__(self):
#         """
#         Joins together the section header and stanza strings with space
#         inbetween.
#         """
#         stanzas = list(self.stanzas)
#         if not stanzas:
#             stanzas = ["# No stanzas defined for this section."]
# 
#         return "\n\n".join(map(str, [self.header] + stanzas))


# Path: tests/haproxy/stanzas/section_tests.py
    import unittest2 as unittest
    import unittest
from lighthouse.haproxy.stanzas.stanza import Stanza
from lighthouse.haproxy.stanzas.section import Section

try:
except ImportError:



class SectionTests(unittest.TestCase):

    def test_no_stanzas(self):
        section = Section("A Section")

        self.assertTrue(
            "# No stanzas defined for this section." in str(section)
        )

    def test_heading(self):
        section = Section("This is a section, ok")

        self.assertTrue(
            str(section).startswith(
                "#\n" +
                "# This is a section, ok\n" +
                "#\n" +
                "\n"
            )
        )

    def test_stanzas(self):

        stanza1 = Stanza("front")