示例#1
0
 def test_adding_text_works_using_set_title(self):
     str_input = """
         group       QGroupBox(hello)
     """
     layouts_created = Builder.build(str_input, 'unit test provenenance')
     widget = layouts_created.at('group')
     self.assertEqual(widget.title(), 'hello')
示例#2
0
 def test_multi_level_descent_and_ascent_works(self):
     str_input = """
         page           QWidget
           vlayout      QVBoxLayout
             a          QLabel
             b          QLabel
             fred       QWidget
               hlayout  QHBoxLayout
                 lbl    QLabel
             c          QLabel
     """
     layouts_created = Builder.build(str_input, 'unit test provenenance')
     dumped = MultilineString.normalise(layouts_created.dump())
     expected = MultilineString.normalise("""
         page                             QWidget
         page.vlayout                     QVBoxLayout
         page.vlayout.a                   QLabel
         page.vlayout.b                   QLabel
         page.vlayout.fred                QWidget
         page.vlayout.fred.hlayout        QHBoxLayout
         page.vlayout.fred.hlayout.lbl    QLabel
         page.vlayout.c                   QLabel
     """)
     self.assertEqual(dumped, expected)
     layout = layouts_created.at('vlayout')
     self.assertEqual(layout.count(), 4)
示例#3
0
 def test_adding_text_works_using_set_text_works(self):
     str_input = """
         label       QLabel(hello)
     """
     layouts_created = Builder.build(str_input, 'unit test provenenance')
     widget = layouts_created.at('label')
     self.assertEqual(widget.text(), 'hello')
示例#4
0
 def test_simplest_possible_creates_parent_child_relations(self):
     str_input = """
         page        QWidget
           layout    QVBoxLayout
     """
     layouts_created = Builder.build(str_input, 'unit test provenenance')
     page = layouts_created.at('page')
     self.assertTrue(isinstance(page.layout(), QVBoxLayout))
示例#5
0
 def test_adding_text_unicode_decode_works(self):
     str_input = """
         page        QWidget
           layout    QHBoxLayout
             label       QLabel(\u25c0)
     """
     layouts_created = Builder.build(str_input, 'unit test provenenance')
     label = layouts_created.at('label')
     txt = label.text()
     self.assertEqual(txt, u'\u25c0')
示例#6
0
 def test_querying_accessor_normal_working(self):
     str_input = """
         layout       QVBoxLayout
           foo_n1     QLabel
           foo_n2     QPushButton
           foo_n3     QTextEdit
     """
     layouts_created = Builder.build(str_input, 'unit test provenenance')
     found = layouts_created.at('foo_n2')
     self.assertTrue(isinstance(found, QPushButton))
示例#7
0
 def test_sibling_child_additions_work(self):
     str_input = """
         layout      QVBoxLayout
           a         QLabel
           b         QLabel
           c         QLabel
     """
     layouts_created = Builder.build(str_input, 'unit test provenenance')
     MultilineString.normalise(layouts_created.dump())
     layout = layouts_created.at('layout')
     self.assertEqual(layout.count(), 3)
示例#8
0
 def test_simplest_possible_dump_of_contents_is_correct(self):
     str_input = """
         page        QWidget
           layout    QVBoxLayout
     """
     layouts_created = Builder.build(str_input, 'unit test provenenance')
     dumped = MultilineString.normalise(layouts_created.dump())
     expected = MultilineString.normalise("""
         page           QWidget
         page.layout    QVBoxLayout
     """)
     self.assertEqual(dumped, expected)
示例#9
0
def build_from_file(file_path, auto_format_and_overwrite=True):
    """
    Builds a QtLayout and QtWidget hierarchy based on the input text provided
    in the input file specified.
    :param file_path:  Full path of input file.
    :param auto_format_and_overwrite: Set this to False to prevent the builder
    from automatically reformatting and overwriting the input file.
    :raises LayoutError:
    :return: A LayoutsCreatedAccessor object.
    """
    one_big_string = file_utils.get_file_contents_as_a_string(file_path)
    layouts_created = Builder.build(one_big_string, file_path)
    if auto_format_and_overwrite:
        re_formatted = ReFormatter.format(one_big_string)
        OriginalFileReWriter.overwrite_original(file_path, re_formatted)
    return LayoutsCreatedAccessor(layouts_created)
示例#10
0
def build_from_multi_line_string(one_big_string, auto_format_and_write_to=''):
    """
    Builds a QtLayout and QtWidget hierarchy based on the input text provided
    in the (multi-line) input string provided.
    :param one_big_string: The input text.
    :param auto_format_and_write_to: Set this to a non-empty file pathname to
    make the builder automatically reformat the input and write the formatted
    input to that file.
    :raises LayoutError:
    :return: A LayoutsCreatedAccessor object.
    """
    layouts_created = Builder.build(one_big_string, 'No input file used')
    if auto_format_and_write_to:
        re_formatted = ReFormatter.format(one_big_string)
        with open(auto_format_and_write_to, 'w') as output_file:
            output_file.write(re_formatted)
    return LayoutsCreatedAccessor(layouts_created)
示例#11
0
 def test_more_than_one_top_level_object_works(self):
     str_input = """
         page1          QWidget
           layout1      QVBoxLayout
         page2          QWidget
           layout2      QVBoxLayout
     """
     layouts_created = Builder.build(str_input, 'unit test provenenance')
     dumped = MultilineString.normalise(layouts_created.dump())
     expected = MultilineString.normalise("""
         page1            QWidget
         page1.layout1    QVBoxLayout
         page2            QWidget
         page2.layout2    QVBoxLayout
     """)
     self.assertEqual(dumped, expected)
     widget = layouts_created.at('page2')
     self.assertTrue(isinstance(widget.layout(), QVBoxLayout))
示例#12
0
 def test_multi_level_descent_works(self):
     str_input = """
         page          QWidget
           layout      QVBoxLayout
             a         QLabel
             b         QLabel
             c         QLabel
     """
     layouts_created = Builder.build(str_input, 'unit test provenenance')
     dumped = MultilineString.normalise(layouts_created.dump())
     expected = MultilineString.normalise("""
         page             QWidget
         page.layout      QVBoxLayout
         page.layout.a    QLabel
         page.layout.b    QLabel
         page.layout.c    QLabel
     """)
     self.assertEqual(dumped, expected)
示例#13
0
    def test_querying_accessor_error_msg_for_none_found(self):
        str_input = """
            layout       QVBoxLayout
              foo        QLabel
              bar        QPushButton
              baz        QTextEdit
        """
        layouts_created = Builder.build(str_input, 'unit test provenance')
        result = raises_layout_error_with_this_message(
            """
            No path can be found that ends with <harry>.
            These are the paths that do exist:

            layout        QVBoxLayout
            layout.foo    QLabel
            layout.bar    QPushButton
            layout.baz    QTextEdit
        """, layouts_created.at, 'harry')
        if not result:
            self.fail()
示例#14
0
 def test_simplest_possible_runs_without_crashing(self):
     str_input = """
         page        QWidget
           layout    QVBoxLayout
     """
     Builder.build(str_input, 'unit test provenenance')