Coder Social home page Coder Social logo

Comments (9)

Lorenzobattistela avatar Lorenzobattistela commented on May 10, 2024 1

Hey @HenriqueAJNB
I was doing some research on pytest and how could we replace this with fixtures. What do you think on something about this (test_pandasai.py)

import pytest

@pytest.fixture
def llm(request):
    return pytest.Mock()

@pytest.fixture
def pandasai(request, llm):
    return PandasAI(llm)

def test_init(pandasai, llm):
    assert pandasai._llm == llm
    assert pandasai._is_conversational_answer is True
    assert pandasai._verbose is False

def test_init_with_llm(pandasai, llm):
    assert pandasai._llm == llm
    assert pandasai._is_conversational_answer is True
    assert pandasai._verbose is False

def test_init_without_llm():
    with pytest.raises(LLMNotFoundError):
        PandasAI()

Haven't tested it yet, but I think you meant something in this sense?

from pandas-ai.

gventuri avatar gventuri commented on May 10, 2024 1

@HenriqueAJNB @Lorenzobattistela merged, feel free to move on! :)

from pandas-ai.

HenriqueAJNB avatar HenriqueAJNB commented on May 10, 2024

Yes, although pytest is not being used at the moment. I've opened this suggestion #26 for changing from unittest to pytest.

from pandas-ai.

Lorenzobattistela avatar Lorenzobattistela commented on May 10, 2024

Let's wait the decision and then we can create a branch to start changing it. I'm willing to contribute

from pandas-ai.

gventuri avatar gventuri commented on May 10, 2024

This would definitely help the way we test it, let's go for it. Does anyone of you @HenriqueAJNB @Lorenzobattistela want to work on it?
Before we pick this one, though, we should work on #26 and have it merged!

from pandas-ai.

Lorenzobattistela avatar Lorenzobattistela commented on May 10, 2024

I want to work on it. I can start working on the fixtures and then if @HenriqueAJNB is picking up #26 we wait for it to be merged to merge this one. Otherwise I can start working on #26 too. Let's wait for his answer

from pandas-ai.

gventuri avatar gventuri commented on May 10, 2024

Ok @Lorenzobattistela I'll assign it to you then! 🎉

from pandas-ai.

Lorenzobattistela avatar Lorenzobattistela commented on May 10, 2024

@gventuri @HenriqueAJNB

Started to work on this, is this the way to go?

import pytest
from typing import Optional
from unittest.mock import Mock, patch
import pandas as pd
from pandasai import PandasAI
from pandasai.exceptions import LLMNotFoundError
from pandasai.llm.fake import FakeLLM

@pytest.fixture
def llm(output: Optional[str] = None):
    return FakeLLM(output=output)

@pytest.fixture
def pandasai(llm):
    return PandasAI(llm)

def test_init(pandasai):
    assert pandasai._llm is not None
    assert pandasai._is_conversational_answer is True
    assert pandasai._verbose is False

def test_init_without_llm():
    with pytest.raises(LLMNotFoundError):
        PandasAI()

def test_conversational_answer(pandasai, llm):
    result = "2"
    llm._output = result
    assert pandasai.conversational_answer(
        "What is the sum of 1 + 1?", "1 + 1", 2
    ) == result

def test_run(pandasai, llm):
        df = pd.DataFrame()
        llm._output = "1"
        assert pandasai.run(df, "What number comes before 2?") == "1"

def test_run_with_conversational_answer(pandasai, llm):
        df = pd.DataFrame()
        llm._output = "1 + 1"
        assert pandasai.run(
            df, "What is the sum of 1 + 1?", is_conversational_answer=True
        ) == "1 + 1"

from pandas-ai.

HenriqueAJNB avatar HenriqueAJNB commented on May 10, 2024

@Lorenzobattistela, as soon as #67 is merged, you are able to go on.

from pandas-ai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.