Exemplo n.º 1
0
def test_load_config_no_unsaved_changed():
    config = {
        "background": "path",
        "Text": [
            {'label': None, "text": "Test", "x": 100, "y": 100}
        ]
    }

    drawer = ConfigDrawer('fake_canvas')
    drawer.add_text(text='sample_text', pos_x=100, pos_y=200, draw=False)
    assert drawer.unsaved_changes

    drawer._load_config(config, config_path='path', draw=False)
    assert not drawer.unsaved_changes
Exemplo n.º 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