Esempio n. 1
0
def test_get_latest_save(reset_db):
    base_date = datetime.today().timestamp()
    # Programs that ran on a past date
    program1_a = TrackedProgram("test1", 100, 200, 300, 0)
    program2_a = TrackedProgram("test2", 100, 300, 375, 25)

    # Tests that the most current program from the current day is retrieved
    time_offset = 100
    program1_b = TrackedProgram("test1", 100, base_date, base_date + 50, 50)
    program1_c = TrackedProgram("test1", 100, base_date + time_offset,
                                base_date + time_offset + 75, 25)
    program2_b = TrackedProgram("test2", 100, base_date + 2 * time_offset,
                                base_date + 2 * time_offset + 100, 0)

    programs = [program1_a, program2_a, program1_b, program2_b, program1_c]
    DataManager.store_many(*programs)

    program1_blank = TrackedProgram.min_init("test1", 100)
    program2_blank = TrackedProgram.min_init("test2", 100)

    latest_1 = DataManager.get_latest_save(program1_blank)
    latest_2 = DataManager.get_latest_save(program2_blank)

    assert latest_1 == program1_c
    assert latest_2 == program2_b
    def test_get_program(self):
        # Tests that a program object with the same name is retrieved from the program_objs
        t1_empty = TrackedProgram.min_init("test1", 1)
        t2_empty = TrackedProgram.min_init("test2", 2)
        t3_empty = TrackedProgram.min_init("test3", 3)
        programs = [t1_empty, t2_empty, t3_empty]

        assert Program.get_program(t1_empty, programs) == t1_empty
        assert Program.get_program(t2_empty, programs) == t2_empty
        assert Program.get_program(t3_empty, programs) == t3_empty
Esempio n. 3
0
def test_get_program_from_arr(state_change_blank_fixture, default_init):
    state_detector = state_change_blank_fixture
    program1 = default_init
    program2 = TrackedProgram.min_init("test2", 200)
    all_programs = [program1, program2]
    state_detector.curr_state = all_programs

    # Retrieves the same program, but may not be the same instance. Is based off of name
    retrieved_pg = Program.get_program(TrackedProgram.min_init("test2", 500),
                                       state_detector.curr_state)
    assert retrieved_pg == program2
Esempio n. 4
0
def test_get_latest_save_empty(reset_db):
    base_date = datetime.today().timestamp()
    # Programs that ran on a past date
    program1_a = TrackedProgram("test1", 100, 200, 300, 0)
    program2_a = TrackedProgram("test2", 100, 300, 375, 25)

    programs = [program1_a, program2_a]
    DataManager.store_many(*programs)

    program1_blank = TrackedProgram.min_init("test1", 100)
    program2_blank = TrackedProgram.min_init("test2", 100)

    latest_1 = DataManager.get_latest_save(program1_blank)
    latest_2 = DataManager.get_latest_save(program2_blank)

    assert latest_1 == None
    assert latest_2 == None
 def test_min_init(self, ):
     pg = TrackedProgram.min_init("test", 10)
     assert pg.name == "test"
     assert pg.max_time == 10
     assert pg.db_id is None
     assert pg.start_time == 0
     assert pg.end_time == 0
     assert pg._time_left == 10.0
     assert pg.blocked is False
Esempio n. 6
0
def test_init_program_objs_with_save_no_db(time_left, expected_left,
                                           expected_block):
    # Tests if there is a saved program and it updates only the time left and blocked status
    test1 = TrackedProgram.min_init("test1", 100)
    test1_saved = TrackedProgram("test1", 100, 50, 60, time_left)

    with patch('manager_core.CurbTheScreen.ProgramStates.tracked_from_settings'
               ) as tracked:
        tracked.return_value = [test1]
        with patch('manager_core.CurbTheScreen.TrackedProgram.has_save_today'
                   ) as has_save:
            has_save.return_value = True
            with patch('manager_core.CurbTheScreen.DataManager.get_latest_save'
                       ) as latest_save:
                latest_save.return_value = test1_saved
                ps = ProgramStates()

                assert ps.program_objs[0].time_left == expected_left
                assert ps.program_objs[0].blocked == expected_block
Esempio n. 7
0
def test_populate_program_pids(states_fixture_full):
    ps = states_fixture_full

    with patch('manager_core.CurbTheScreen.psutil.process_iter'
               ) as mocked_process_iter:
        with patch(
                'manager_core.CurbTheScreen.psutil.Process') as mocked_process:
            temp_program = TrackedProgram.min_init("test1", 100)

            # Tests when pids are added that match the name of the program
            mocked_process.info = {"name": 'test1', "pid": 1}
            mocked_process_iter.return_value = iter([mocked_process])
            ps.populate_program_pids()
            mocked_process_iter.assert_called_with(attrs=["name", "pid"])

            assert [1] == ps.get_program(temp_program).PIDS

            mocked_process.info = {"name": 'test1', "pid": 2}
            mocked_process_iter.return_value = iter([mocked_process])
            ps.populate_program_pids()

            assert [1, 2] == ps.get_program(temp_program).PIDS

            # Tests that the program is retrieved when it contains the name of the program
            mocked_process.info = {"name": 'Containstest1', "pid": 3}
            mocked_process_iter.return_value = iter([mocked_process])

            ps.populate_program_pids()
            assert [1, 2, 3] == ps.get_program(temp_program).PIDS

            # Tests when the name is not contained
            # Tests that the program is retrieved when it contains the name of the program
            mocked_process.info = {"name": 'test42', "pid": 10}
            mocked_process_iter.return_value = iter([mocked_process])

            ps.populate_program_pids()
            assert [1, 2, 3] == ps.get_program(temp_program).PIDS
 def test_max_time_setter(self):
     pg = TrackedProgram.min_init("test1", 90)
     pg.max_time = 100
     assert pg.max_time == 100
 def test_name_setter(self):
     pg = TrackedProgram.min_init("test1", 90)
     pg.name = "test2"
     assert pg.name == "test2"
Esempio n. 10
0
 def test_time_left_setter(self):
     pg = TrackedProgram.min_init("test1", 90)
     pg.time_left = 100
     assert pg.time_left == 100
Esempio n. 11
0
def example_pg_class():
    pg = Program(TrackedProgram.min_init("test", 100))
    return pg
Esempio n. 12
0
def default_init():
    return TrackedProgram.min_init("test", 100)