#!/usr/bin/env python3

from bio96 import *
nan = float("NaN")

def row(df, q):
    return df.query(q).iloc[0].dropna().to_dict()


def test_one_well():
    wells = {
            'A1': {'x': 1},
    }
    df = table_from_wells(wells, {})
    assert row(df, 'well == "A1"') == dict(
            well='A1', row='A', col='1', row_i=0, col_j=0, x=1)

def test_different_parameters():
    # We should get NaN `y` in A1 and `x` in B1.
    wells = {
            'A1': {'x': 1},
            'B1': {'y': 2},
    }
    df = table_from_wells(wells, {})
    assert row(df, 'well == "A1"') == dict(
            well='A1', row='A', col='1', row_i=0, col_j=0, x=1)
    assert row(df, 'well == "B1"') == dict(
            well='B1', row='B', col='1', row_i=1, col_j=0, y=2)

def test_index():
    wells = {
            'A1': {'x': 1},
            'B1': {'x': 2},
    }
    df = table_from_wells(wells, {'plate': 'Z'})
    assert row(df, 'well == "A1"') == dict(
            plate='Z', well='A1', row='A', col='1', row_i=0, col_j=0, x=1)
    assert row(df, 'well == "B1"') == dict(
            plate='Z', well='B1', row='B', col='1', row_i=1, col_j=0, x=2)

