Best Python code snippet using pandera_python
test_data.py
Source: test_data.py
2import pytest3import pandas as pd4from ..data import (limit_rows, MaxRowsError, sample, pipe, to_values,5 to_json, to_csv)6def _create_dataframe(N):7 data = pd.DataFrame({"x": range(N), "y": range(N)})8 return data9def _create_data_with_values(N):10 data = {'values': [{'x': i, 'y': i+1} for i in range(N)]}11 return data12def test_limit_rows():13 """Test the limit_rows data transformer."""14 data = _create_dataframe(10)15 result = limit_rows(data, max_rows=20)16 assert data is result17 with pytest.raises(MaxRowsError):18 pipe(data, limit_rows(max_rows=5))19 data = _create_data_with_values(10)20 result = pipe(data, limit_rows(max_rows=20))21 assert data is result22 with pytest.raises(MaxRowsError):23 limit_rows(data, max_rows=5)24def test_sample():25 """Test the sample data transformer."""26 data = _create_dataframe(20)27 result = pipe(data, sample(n=10))28 assert len(result)==1029 assert isinstance(result, pd.DataFrame)30 data = _create_data_with_values(20)31 result = sample(data, n=10)32 assert isinstance(result, dict)33 assert 'values' in result34 assert len(result['values'])==1035 data = _create_dataframe(20)36 result = pipe(data, sample(frac=0.5))37 assert len(result)==1038 assert isinstance(result, pd.DataFrame)39 data = _create_data_with_values(20)40 result = sample(data, frac=0.5)41 assert isinstance(result, dict)42 assert 'values' in result43 assert len(result['values'])==1044def test_to_values():45 """Test the to_values data transformer."""46 data = _create_dataframe(10)47 result = pipe(data, to_values)48 assert result=={'values': data.to_dict(orient='records')}49def test_type_error():50 """Ensure that TypeError is raised for types other than dict/DataFrame."""51 for f in (sample, limit_rows, to_values):52 with pytest.raises(TypeError):53 pipe(0, f)54def test_dataframe_to_json():55 """Test to_json56 - make certain the filename is deterministic57 - make certain the file contents match the data58 """59 data = _create_dataframe(10)60 try:61 result1 = pipe(data, to_json)62 result2 = pipe(data, to_json)63 filename = result1['url']64 output = pd.read_json(filename)65 finally:66 os.remove(filename)67 assert result1 == result268 assert output.equals(data)69def test_dict_to_json():70 """Test to_json71 - make certain the filename is deterministic72 - make certain the file contents match the data73 """74 data = _create_data_with_values(10)75 try:76 result1 = pipe(data, to_json)77 result2 = pipe(data, to_json)78 filename = result1['url']79 output = pd.read_json(filename).to_dict(orient='records')80 finally:81 os.remove(filename)82 assert result1 == result283 assert data == {'values': output}84def test_dataframe_to_csv():85 """Test to_csv with dataframe input86 - make certain the filename is deterministic87 - make certain the file contents match the data88 """89 data = _create_dataframe(10)90 try:91 result1 = pipe(data, to_csv)92 result2 = pipe(data, to_csv)93 filename = result1['url']94 output = pd.read_csv(filename)95 finally:96 os.remove(filename)97 assert result1 == result298 assert output.equals(data)99def test_dict_to_csv():100 """Test to_csv with dict input101 - make certain the filename is deterministic102 - make certain the file contents match the data103 """...
Check out the latest blogs from LambdaTest on this topic:
Sometimes, in our test code, we need to handle actions that apparently could not be done automatically. For example, some mouse actions such as context click, double click, drag and drop, mouse movements, and some special key down and key up actions. These specific actions could be crucial depending on the project context.
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Unit and functional testing are the prime ways of verifying the JavaScript code quality. However, a host of tools are available that can also check code before or during its execution in order to test its quality and adherence to coding standards. With each tool having its unique features and advantages contributing to its testing capabilities, you can use the tool that best suits your need for performing JavaScript testing.
I was once asked at a testing summit, “How do you manage a QA team using scrum?” After some consideration, I realized it would make a good article, so here I am. Understand that the idea behind developing software in a scrum environment is for development teams to self-organize.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!