示例#1
0
def test_get_widget_with_label():
    drawer = ConfigDrawer('fake_canvas')

    assert not drawer.get_widget_with_label('myLabel')

    widget = drawer.add_input_box(label='myLabel', pos_x=200, pos_y=300, draw=False)
    assert drawer.get_widget_with_label('myLabel') == widget
示例#2
0
def test_save_load_config_identical(monkeypatch):
    def mock_json_save(mock, mock2):
        None
    monkeypatch.setattr(imgloader, 'dump_json', mock_json_save)

    # Create 1 Config from Blank $ Confirm empty, Add Text, Add Buttons
    drawer1 = ConfigDrawer('fake_canvas')
    drawer1.load_background('path', draw=False)

    # Add all widgets
    drawer1.add_text(label='myText', text='sample_text', pos_x=100, pos_y=200, draw=False)
    drawer1.add_image_button(label='button', pos_x=100, pos_y=200, orig_on_release=True, images=['path1'], draw=False)
    drawer1.add_input_box(label='box', pos_x=100, pos_y=200, draw=False)

    button2 = drawer1.add_image_button(pos_x=100, pos_y=200, orig_on_release=False, images=['path1', 'path2'], draw=False)
    button2.next_image()

    # Save the Config
    drawer1.save_config_to_file('fake_path')

    # Copy the saved config
    config_copy = copy.deepcopy(drawer1.saved_img_config)

    # Create Config 2 & Confirm Empty
    drawer2 = ConfigDrawer('fake_canvas')
    d2_config = drawer2.calc_config_dict()

    # Load Config
    drawer2._load_config(config_copy, config_path='fake_path', draw=False)

    # Check can find our Label
    widget = drawer2.get_widget_with_label('myText')
    assert widget is not None

    print(drawer1.calc_config_dict())
    print(drawer2.calc_config_dict())

    # Check both configs the same
    assert drawer1 == drawer2