Esempio n. 1
0
def test_file_action_with_values():
    filepath = Path("fake/test.odt")
    action = FileAction("Mocking", filepath, 42)
    assert action.type == "Mocking"

    # Test repr() when .get_percent() equals 0
    assert repr(action) == "Mocking('test.odt'[42])"

    # Will test .get_percent()
    details = action.export()
    assert details["size"] == 42
    assert details["name"] == "test.odt"
    assert details["filepath"] == f"fake{os.path.sep}test.odt"

    # Test progress property setter when .progress < .size
    action.progress = 24.5
    details = action.export()
    assert details["progress"] == 24.5 * 100 / 42.0

    # Test progress property setter when .progress >= .size
    action.progress = 222.0
    details = action.export()
    assert details["progress"] == 100.0
    assert details["uploaded"]

    Action.finish_action()
Esempio n. 2
0
def test_file_action(tmp):
    parent = tmp()
    parent.mkdir()
    filepath = parent / "test.txt"
    size = filepath.write_bytes(b"This is Sparta!")

    action = FileAction("Mocking", filepath, size)
    assert action.type == "Mocking"
    assert not action.empty

    # Will test .get_percent()
    details = action.export()
    assert details["action_type"] == "Mocking"
    assert details["progress"] == 0.0
    assert isinstance(details["uid"], str)
    assert details["size"] == size
    assert details["name"] == filepath.name
    assert details["filepath"] == str(filepath)

    assert Action.get_current_action() is action

    # Test repr() when .get_percent() > 0
    action.size = 42
    action.progress = 4.2
    assert repr(action) == "Mocking('test.txt'[42]-10.0)"

    Action.finish_action()
    assert action.finished
Esempio n. 3
0
def test_file_action_with_values():
    filepath = Path("fake/test.odt")
    action = FileAction("Mocking", filepath, size=42)
    assert action.type == "Mocking"

    # Will test .get_percent()
    details = action.export()
    assert details["size"] == 42
    assert details["name"] == "test.odt"
    assert details["filepath"] == f"fake{os.path.sep}test.odt"
Esempio n. 4
0
def test_file_action_empty_file(tmp):
    parent = tmp()
    parent.mkdir()
    filepath = parent / "test.txt"
    filepath.touch()

    action = FileAction("Mocking", filepath, filepath.stat().st_size)

    assert action.empty
    assert not action.uploaded
    details = action.export()
    assert details["action_type"] == "Mocking"
    assert details["progress"] == 0.0
    assert isinstance(details["uid"], str)
    assert details["size"] == 0
    assert details["name"] == filepath.name
    assert details["filepath"] == str(filepath)

    # Trigger a progression update telling that the file has been uploaded
    action.progress += 0
    assert action.export()["progress"] == 100.0
    assert action.uploaded

    Action.finish_action()
Esempio n. 5
0
def test_file_action_inexistant_file(tmp):
    parent = tmp()
    parent.mkdir()
    filepath = parent / "test.txt"

    action = FileAction("Mocking", filepath, 0)
    assert action.empty
    assert not action.uploaded

    details = action.export()
    assert details["action_type"] == "Mocking"
    assert details["progress"] == 0.0
    assert isinstance(details["uid"], str)
    assert details["size"] == 0
    assert details["name"] == filepath.name
    assert details["filepath"] == str(filepath)

    Action.finish_action()
Esempio n. 6
0
def test_file_action(tmp):
    parent = tmp()
    parent.mkdir()
    filepath = parent / "test.txt"
    size = filepath.write_bytes(b"This is Sparta!")

    action = FileAction("Mocking", filepath)
    assert action.type == "Mocking"

    # Will test .get_percent()
    details = action.export()
    assert details["last_transfer"] == "Mocking"
    assert details["progress"] == 0.0
    assert isinstance(details["uid"], str)
    assert details["size"] == size
    assert details["name"] == filepath.name
    assert details["filepath"] == str(filepath)

    assert Action.get_current_action() == action

    Action.finish_action()
    assert action.finished