def test_not_a_layout_or_widget(self): finder = None maker = QObjectMaker(finder) result = raises_layout_error_with_this_message(""" This class name: <QColor>, instantiates successfully, but is neither a QLayout nor a QWidget. """, maker.make, 'fred', 'QColor') if not result: self.fail()
def test_finding_error_handling_when_nothing_found(self): finder = WidgetAndLayoutFinder() maker = QObjectMaker(finder) result = raises_layout_error_with_this_message(""" Cannot find any objects of class <CustomLayout>, that are referenced by a variable or attribute called <wont_find_me> """, maker.make, 'wont_find_me', '?CustomLayout') if not result: self.fail()
def test_error_message_when_no_meaningful_input_found(self): str_input = """ # Hello """ result = raises_layout_error_with_this_message( """ This input provided (unit test provenance) contains nothing, or nothing except whitespace and comments. """, Builder.build, str_input, 'unit test provenance') if not result: self.fail()
def test_error_message_when_tabs_are_present(self): str_input = """ page \t QLabel """ result = raises_layout_error_with_this_message( """ This line contains a tab - which is not allowed. (This line: <page \t QLabel>) (Line number: 1, from unit test provenance) """, Builder.build, str_input, 'unit test provenance') if not result: self.fail()
def test_cannot_instantiate(self): finder = None maker = QObjectMaker(finder) result = raises_layout_error_with_this_message(""" Cannot instantiate one of these: <__name__>. It is supposed to be the name a a QLayout or QWidget class, that can be used as a constructor. The error coming back from Python is: 'str' object is not callable. """, maker.make, 'fred', '__name__') if not result: self.fail()
def test_error_message_when_too_few_words_per_line(self): str_input = """ page """ result = raises_layout_error_with_this_message( """ Cannot split this line, into exactly two words, (after comments and parenthesis have been removed.) (This line: <page>) (Line number: 1, from unit test provenance) """, Builder.build, str_input, 'unit test provenance') if not result: self.fail()
def test_error_message_when_indent_is_not_multiple_of_two(self): str_input = """ page QLabel layout QHBoxLayout """ result = raises_layout_error_with_this_message( """ A line is indented by 1 spaces. Indentation spaces must be a multiple of 2. (This line: < layout QHBoxLayout>) (Line number: 2, from unit test provenance) """, Builder.build, str_input, 'unit test provenance') if not result: self.fail()
def test_error_message_when_skip_indent_levels(self): str_input = """ page QWidget layout QVBoxLayout """ result = raises_layout_error_with_this_message( """ This line is indented too much. It cannot be indented relative to the line above it by more than 2 spaces. (This line: < layout QVBoxLayout>) (Line number: 2, from unit test provenance) """, Builder.build, str_input, 'unit test provenance') if not result: self.fail()
def test_error_message_when_set_text_fails(self): # You can't call setText('hello') on a QVBoxLayout. str_input = """ layout QVBoxLayout(hello) """ result = raises_layout_error_with_this_message( """ Cannot do anything with the text you specified in parenthesis because the object being created has neither of the following methods: setText(), or setTitle(). (This line: <layout QVBoxLayout(hello)>) (Line number: 1, from unit test provenance) """, Builder.build, str_input, 'unit test provenance') if not result: self.fail()
def test_finding_error_handling_when_duplicates_found(self): # Create two items that should get found and thus be duplicates. # Assign them the local variables to defeat immediate GC. my_page = CustomLayout() arbitrary = HasTargetIn() finder = WidgetAndLayoutFinder() maker = QObjectMaker(finder) result = raises_layout_error_with_this_message(""" Ambiguity problem. Found more than one object of class: <CustomLayout>, referenced by a variable or attribute called: <my_page> """, maker.make, 'my_page', '?CustomLayout') if not result: self.fail()
def test_error_message_when_name_is_not_unique(self): # Names must be unique. str_input = """ foo QVBoxLayout bar QGroupBox bar QLabel """ result = raises_layout_error_with_this_message( """ The name you have given this item (<bar>), has already been used. (This line: < bar QLabel>) (Line number: 3, from unit test provenance) """, Builder.build, str_input, 'unit test provenance') if not result: self.fail()
def test_unrecognized_class(self): # Specify the required class as HBoxLayout (omitting the Q) finder = None maker = QObjectMaker(finder) result = raises_layout_error_with_this_message(""" Python cannot find this word in the QtGui namespace: <HBoxLayout>, Did you mean one of these: QHBoxLayout QBoxLayout QVBoxLayout QLayout QTextLayout QFormLayout """, maker.make, 'fred', 'HBoxLayout') if not result: self.fail()
def test_error_handling_when_speculative_methods_all_fail(self): # There is no way to add a widget to a widget. result = raises_layout_error_with_this_message( """ Could not add this child: <fred> to its parent. The child is a: <QWidget> The parent is a: <QWidget> None of the following addition methods worked: addLayout setLayout addWidget addTab setWidget addSpacerItem """, ChildAdder.add, QWidget(), 'fred', QWidget()) if not result: self.fail()
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()