示例#1
0
def test_update_mapping():
    object_tracker = ObjectTracker()
    do = DummyObject()
    do_id, _ = object_tracker.track(do)
    # The object is being tracked
    written = object_tracker.has_been_written(do_id)
    assert (
        written is False
    ), "The object identifier must not be in written_objects after tracking."  # noqa: E501
    object_tracker.update_mapping(do_id, do)
    new_id = object_tracker.get_object_id(do)
    assert (
        do_id != new_id
    ), "The identifiers must not be equal after updating the mapping."  # noqa: E501
    written = object_tracker.has_been_written(new_id)
    assert (
        written is True
    ), "The object's new identifier must be in written_objects after updating its mapping."  # noqa: E501
    file_name = object_tracker.pop_written_obj(new_id)
    assert file_name is not None, "The object file name must not be None."
    assert isinstance(file_name, str), "The object file name must be string."
    assert file_name != "", "The object file name must not be empty."
    written = object_tracker.has_been_written(new_id)
    assert (
        written is False
    ), "The object's new identifier must not be in written_objects after popping."  # noqa: E501
示例#2
0
def test_get_object_id():
    object_tracker = ObjectTracker()
    do = DummyObject()
    do_id, do_file_name = object_tracker.track(do)
    do_get_obj_id = object_tracker.get_object_id(do)
    assert do_id == do_get_obj_id, "The object identifiers are different!"
    assert do_file_name != "", ERROR_FILENAME_EMPTY
示例#3
0
def test_not_tracking_not_empty():
    object_tracker = ObjectTracker()
    do = DummyObject()
    _, _ = object_tracker.track(do)
    do2 = DummyObject()
    assert (object_tracker.is_tracked(do2) is
            None), "The object seems to be tracked."  # noqa: E501
示例#4
0
def test_pending_to_synchronize():
    object_tracker = ObjectTracker()
    do = DummyObject()
    do_id, _ = object_tracker.track(do)
    # The object is being tracked
    pending = object_tracker.is_pending_to_synchronize(do_id)
    assert pending is True, "The object must be pending to synchronize after tracking."  # noqa: E501
示例#5
0
def test_get_object_id():
    object_tracker = ObjectTracker()
    do = DummyObject()
    do_id, do_file_name = object_tracker.track(do)
    do_get_obj_id = object_tracker.get_object_id(do)
    assert do_id == do_get_obj_id, "The object identifiers are different!"
    assert do_file_name != "", "The file name can not be empty."
示例#6
0
def test_get_all_file_names():
    object_tracker = ObjectTracker()
    do = DummyObject()
    do2 = DummyObject()
    _, _ = object_tracker.track(do)
    _, _ = object_tracker.track(do2)
    file_names = object_tracker.get_all_file_names()
    assert len(file_names) == 2, "Two elements should be being tracked."
示例#7
0
def test_clean_object_tracker():
    object_tracker = ObjectTracker()
    do = DummyObject()
    _, _ = object_tracker.track(do)
    object_tracker.clean_object_tracker()
    assert len(object_tracker.pending_to_synchronize) == 0
    assert len(object_tracker.file_names) == 0
    assert len(object_tracker.written_objects) == 0
    assert len(object_tracker.obj_id_to_obj) == 0
    assert len(object_tracker.address_to_obj_id) == 0
示例#8
0
def test_get_file_name():
    object_tracker = ObjectTracker()
    do = DummyObject()
    do_id, do_file_name = object_tracker.track(do)
    file_name = object_tracker.get_file_name(do_id)
    assert file_name is not None, "The file name can not be None."
    assert isinstance(file_name, str), "The file name must be a string."
    assert file_name != "", "The file name must not be empty."
    assert do_file_name != "", ERROR_FILENAME_EMPTY
    assert do_file_name == file_name, "The file name received wrong file name."
示例#9
0
def test_track():
    object_tracker = ObjectTracker()
    do = DummyObject()
    do_id, do_file_name = object_tracker.track(do)
    assert (object_tracker.is_tracked(do)
            is not None), ERROR_ID_NONE  # noqa: E501
    assert isinstance(object_tracker.is_tracked(do),
                      str), ERROR_ID_STRING  # noqa: E501
    assert (object_tracker.is_tracked(do) != ""), ERROR_ID_EMPTY  # noqa: E501
    assert (object_tracker.is_tracked(do) == do_id
            ), ERROR_ID_DIFFERENT  # noqa: E501
    assert do_file_name != "", ERROR_FILENAME_EMPTY
示例#10
0
def test_track():
    object_tracker = ObjectTracker()
    do = DummyObject()
    do_id, do_file_name = object_tracker.track(do)
    assert object_tracker.is_tracked(
        do) is not None, "The identifier can not be None."  # noqa: E501
    assert isinstance(object_tracker.is_tracked(do),
                      str), "The identifier must be a string."  # noqa: E501
    assert object_tracker.is_tracked(
        do) != "", "The identifier must not be empty."  # noqa: E501
    assert object_tracker.is_tracked(
        do
    ) == do_id, "Tracked identifier differs from returned by track function."  # noqa: E501
    assert do_file_name != "", "The file name can not be empty."
示例#11
0
def test_track_collection():
    object_tracker = ObjectTracker()
    my_collection = [DummyObject(), DummyObject()]
    collection_id, collection_file_name = object_tracker.track(
        my_collection, collection=True)  # noqa: E501
    assert (object_tracker.is_tracked(my_collection)
            is not None), ERROR_ID_NONE  # noqa: E501
    assert isinstance(object_tracker.is_tracked(my_collection),
                      str), ERROR_ID_STRING  # noqa: E501
    assert (object_tracker.is_tracked(my_collection) !=
            ""), ERROR_ID_EMPTY  # noqa: E501
    assert (object_tracker.is_tracked(my_collection) == collection_id
            ), ERROR_ID_DIFFERENT  # noqa: E501
    assert (collection_file_name is
            None), "The file name must be None for collections."  # noqa: E501
示例#12
0
def test_stop_tracking():
    object_tracker = ObjectTracker()
    do = DummyObject()
    do_id, do_file_name = object_tracker.track(do)
    assert (object_tracker.is_tracked(do)
            is not None), ERROR_ID_NONE  # noqa: E501
    assert isinstance(object_tracker.is_tracked(do),
                      str), ERROR_ID_STRING  # noqa: E501
    assert (object_tracker.is_tracked(do) != ""), ERROR_ID_EMPTY  # noqa: E501
    assert (object_tracker.is_tracked(do) == do_id
            ), ERROR_ID_DIFFERENT  # noqa: E501
    # The object do is being tracked
    object_tracker.stop_tracking(do)
    assert (object_tracker.is_tracked(do) is None
            ), "The identifier must be None after stop tracking"  # noqa: E501
    assert do_file_name != "", ERROR_FILENAME_EMPTY
示例#13
0
def test_track_collection():
    object_tracker = ObjectTracker()
    my_collection = [DummyObject(), DummyObject()]
    collection_id, collection_file_name = object_tracker.track(
        my_collection, collection=True)  # noqa: E501
    assert object_tracker.is_tracked(
        my_collection
    ) is not None, "The identifier can not be None."  # noqa: E501
    assert isinstance(object_tracker.is_tracked(my_collection),
                      str), "The identifier must be a string."  # noqa: E501
    assert object_tracker.is_tracked(
        my_collection) != "", "The identifier must not be empty."  # noqa: E501
    assert object_tracker.is_tracked(
        my_collection
    ) == collection_id, "Tracked identifier differs from returned by track function."  # noqa: E501
    assert collection_file_name is None, "The file name must be None for collections."  # noqa: E501
示例#14
0
def test_report():
    object_tracker = ObjectTracker()
    object_tracker.enable_report()
    assert (object_tracker.is_report_enabled() is
            True), "Reporting must be enabled."  # noqa: E501
    do = DummyObject()
    _, _ = object_tracker.track(do)
    object_tracker.stop_tracking(do)
    object_tracker.generate_report(".")
    report = "object_tracker.png"
    generated = os.path.exists(report) and os.path.isfile(report)
    assert (generated is
            True), "Report result image has not been generated."  # noqa: E501
    if generated:
        os.remove(report)
    object_tracker.clean_report()
    assert (len(object_tracker.reporting_info) == 0
            ), "The reporting info list has not been cleared!"  # noqa: E501
示例#15
0
def test_stop_tracking_collection():
    object_tracker = ObjectTracker()
    my_collection = [DummyObject(), DummyObject()]
    collection_id, collection_file_name = object_tracker.track(my_collection,
                                                               collection=True)
    assert (object_tracker.is_tracked(my_collection)
            is not None), ERROR_ID_NONE  # noqa: E501
    assert isinstance(object_tracker.is_tracked(my_collection),
                      str), ERROR_ID_STRING  # noqa: E501
    assert (object_tracker.is_tracked(my_collection) !=
            ""), ERROR_ID_EMPTY  # noqa: E501
    assert (object_tracker.is_tracked(my_collection) == collection_id
            ), ERROR_ID_DIFFERENT  # noqa: E501
    # The collection is being tracked
    object_tracker.stop_tracking(my_collection, collection=True)
    assert (object_tracker.is_tracked(my_collection) is None
            ), "The identifier must be None after stop tracking"  # noqa: E501
    assert (collection_file_name is
            None), "The file name must be None for collections."  # noqa: E501
示例#16
0
def test_not_tracking_empty():
    object_tracker = ObjectTracker()
    do = DummyObject()
    assert object_tracker.is_tracked(
        do) is None, "The object seems to be tracked."  # noqa: E501
示例#17
0
def test_obj_not_pending_to_synchronize():
    object_tracker = ObjectTracker()
    do = DummyObject()
    # The object is being tracked
    pending = object_tracker.is_obj_pending_to_synchronize(do)
    assert pending is False, "The object should not be pending to synchronize."
示例#18
0
def test_not_pending_to_synchronize():
    object_tracker = ObjectTracker()
    # The object is being tracked
    pending = object_tracker.is_pending_to_synchronize("IMPOSSIBLE_ID")
    assert pending is False, "The object should not be pending to synchronize."