def test_ViewTrainmoveClass_add_vobcfault(): c = ViewTrainmoveClass(135, '2015-1-12 00:07', 0, timedelta(hours=0)) c.add_vobc_fault(0) fig = c.get_fig() assert fig is not None assert util.IsInMemoryTrue(len(fig.data) == 0)
def test_ViewTrainmoveClass_add_commLoss(): c = ViewTrainmoveClass(135, '2015-1-12 00:07', 0, timedelta(hours=0)) c.add_commLoss(0) fig = c.get_fig() assert fig is not None assert len(fig.data) >= 0 assert (fig.data[0].name == 'Vobc Comm Loss') assert isinstance(fig.data[0], plotly.graph_objs.Scatter)
def test_ViewTrainmoveClass_add_door(): c = ViewTrainmoveClass(135, '2015-1-12 00:07', 0, timedelta(hours=0)) c.add_door_data(0) fig = c.get_fig() assert fig is not None assert len(fig.data) == 2 assert (fig.data[0].name == 'Door Cmd') assert isinstance(fig.data[0], plotly.graph_objs.Scatter) assert (fig.data[1].name == 'Door Status') assert isinstance(fig.data[1], plotly.graph_objs.Scatter)
def test_ViewTrainmoveClass_add_velocity(): c = ViewTrainmoveClass(135, '2015-1-12 00:07', 0, timedelta(hours=0)) c.add_velocity_data(0) fig = c.get_fig() assert fig is not None assert len( fig.data ) >= 2 #At least should have 2 elements: one Max, one Actual. When more active/passive exist, will have more trace assert (fig.data[0].name == 'Actual Velocity') assert isinstance(fig.data[1], plotly.graph_objs.Scatter) assert (fig.data[1].name == 'Max Velocity')
def test_ViewTrainmoveClass_door_cmd_status(): c = ViewTrainmoveClass(135, '2015-1-12 00:07', 0, timedelta(hours=0)) df = c.trainmove_df['Door Status Tips'].unique() assert len(df) == 2 assert df[0] in ['Door Status = Closed', 'Door Status = Open'] assert df[1] in ['Door Status = Closed', 'Door Status = Open'] df = c.trainmove_df['Door Cmd Tips'].unique() assert len(df) == 2 assert df[0] in ['Door Cmd = Closed', 'Door Cmd = Open'] assert df[1] in ['Door Cmd = Closed', 'Door Cmd = Open']
def display_figure_trainmove(table_active_cell, table_data, timewindow_value): fault_code = None p_train_id = None op_date = None offset = 0 if timewindow_value != None: offset = timewindow_value['offset'] delta = timedelta(hours=offset / 2) if table_data is not None and len( table_data) != 0 and table_active_cell is not None and len( table_data) > table_active_cell['row']: op_date = table_data[table_active_cell['row']]['loggedAt'] p_train_id = table_data[table_active_cell['row']]['parentTrainId'] fault_code = table_data[table_active_cell['row']]['faultCode'] c = ViewTrainmoveClass(p_train_id, op_date, fault_code, delta) c.create_fig() fig = c.get_fig() return fig
def test_ViewTrainmoveClass_no_data(): c = ViewTrainmoveClass(135, '2015-1-12 00:07', 0, timedelta(hours=0)) c.start = datetime(2020, 1, 1, 1, 0, 0) c.end = datetime(2020, 1, 1, 2, 0, 0) c.update_figure_layout() fig = c.get_fig() assert fig is not None assert fig.layout.xaxis.range[0] == c.start assert fig.layout.xaxis.range[1] == c.end
def create_fig_by_trainmove(vobc_id, op_date, fault_code, offset=0): c = ViewTrainmoveClass(vobc_id, op_date, fault_code, offset) c.create_fig() return c.get_fig()
def test_ViewTrainmoveClass_offset(): c = ViewTrainmoveClass(135, '2015-1-12 00:07', 0, timedelta(hours=0)) c.create_fig() assert c.get_fig() != None
def test_ViewTrainmoveClass_private_exception(): c = ViewTrainmoveClass(135, '2015-1-12 00:07', 0, timedelta(hours=0)) with pytest.raises(AttributeError) as exception_info: c.__read_base_data() assert 'has no attribute' in str(exception_info.value)