Ejemplo n.º 1
0
    def change_systray_icon(self):
        syncing = False
        engines = self.manager.get_engines()
        invalid_credentials = True
        paused = True
        offline = True

        for engine in engines.itervalues():
            syncing |= engine.is_syncing()
            invalid_credentials &= engine.has_invalid_credentials()
            paused &= engine.is_paused()
            offline &= engine.is_offline()

        if offline:
            new_state = 'stopping'
            Action(Translator.get('OFFLINE'))
        elif invalid_credentials:
            new_state = 'stopping'
            Action(Translator.get('INVALID_CREDENTIALS'))
        elif not engines or paused:
            new_state = 'disabled'
            Action.finish_action()
        elif syncing:
            new_state = 'transferring'
        else:
            new_state = 'asleep'
            Action.finish_action()

        self.set_icon_state(new_state)
Ejemplo n.º 2
0
def test_action():
    action = Action("Testing")
    assert action.type == "Testing"
    assert repr(action)
    assert "%" not in repr(action)

    actions = Action.get_actions()
    assert len(actions) == 1
    assert list(actions.values())[0] == action
    assert Action.get_current_action() == action

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

    Action.finish_action()
    actions = Action.get_actions()
    assert len(actions) == 0
    assert Action.get_current_action() is None
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 def end_action(self):
     Action.finish_action()
Ejemplo n.º 5
0
 def _end_action(self):
     Action.finish_action()
     self._action = None
Ejemplo n.º 6
0
def test_action_with_values():
    action = Action(action_type="Trying", progress=42.222)
    assert "%" in repr(action)
    details = action.export()
    assert details["progress"] == 42.222
    Action.finish_action()
Ejemplo n.º 7
0
 def _end_action(self):
     Action.finish_action()
     self._action = None
 def end_action():
     Action.finish_action()
Ejemplo n.º 9
0
def test_action_with_values():
    action = Action("Trying", progress=42.222)
    assert "%" in repr(action)
    details = action.export()
    assert details["progress"] == 42.222
    Action.finish_action()