测试组织#

理想情况下,测试应该有且只有一个明显的位置。在我们实现这一理想之前,以下是关于测试应该在哪里进行的一些经验法则。

  1. 您的测试是否仅依赖 pd._libs.tslibs ?此测试可能属于以下某一项:

    • tests.tslibs

      备注

      中没有文件 tests.tslibs 应从外部的任何Pandas模块导入 pd._libs.tslibs

    • tests.scalar

    • tests.tseries.offsets

  2. 您的测试是否仅依赖pd._libs中的代码?此测试可能属于以下某一项:

    • tests.libs

    • tests.groupby.test_libgroupby

  3. 你的测试是算术法还是比较法?此测试可能属于以下某一项:

    • tests.arithmetic

      备注

      这些测试旨在用于可共享的测试,以使用 box_with_array 固定装置。

    • tests.frame.test_arithmetic

    • tests.series.test_arithmetic

  4. 您的测试是否采用了减法(最小、最大、总和、求和、求和等)?此测试可能属于以下某一项:

    • tests.reductions

      备注

      这些测试旨在用于可共享的测试,以测试DataFrame/Series/Index/ExtensionArray的行为。

    • tests.frame.test_reductions

    • tests.series.test_reductions

    • tests.test_nanops

  5. 您的测试是针对索引方法的吗?这是决定测试属于哪里的最困难的情况,因为有许多这样的测试,并且其中许多测试不止一种方法(例如,两者都测试 Series.__getitem__Series.loc.__getitem__ )

    1. 测试是否专门测试索引方法(例如 Index.get_locIndex.get_indexer )?此测试可能属于以下某一项:

      • tests.indexes.test_indexing

      • tests.indexes.fooindex.test_indexing

      在该文件中应该有一个特定于方法的测试类,例如 TestGetLoc

      在大多数情况下,两者都不是 Series 也不是 DataFrame 在这些测试中应该需要对象。

    2. 是对Series或DataFrame索引方法的测试 其他__getitem____setitem__ ,例如 xswheretakemasklookup ,或 insert ?此测试可能属于以下某一项:

      • tests.frame.indexing.test_methodname

      • tests.series.indexing.test_methodname

    3. 是对以下任何一个的测试 locilocat ,或 iat ?此测试可能属于以下某一项:

      • tests.indexing.test_loc

      • tests.indexing.test_iloc

      • tests.indexing.test_at

      • tests.indexing.test_iat

      在适当的文件中,测试类对应于任一类型的索引器(例如 TestLocBooleanMask )或主要用例(例如 TestLocSetitemWithExpansion )。

      关于测试多种索引方法的测试,请参见D)部分中的注释。

    4. 是不是测试 Series.__getitem__Series.__setitem__DataFrame.__getitem__ ,或 DataFrame.__setitem__ ?此测试可能属于以下某一项:

      • tests.series.test_getitem

      • tests.series.test_setitem

      • tests.frame.test_getitem

      • tests.frame.test_setitem

      如果许多情况下,这种测试可能会测试多种类似的方法,例如

      import pandas as pd
      import pandas._testing as tm
      
      def test_getitem_listlike_of_ints():
          ser = pd.Series(range(5))
      
          result = ser[[3, 4]]
          expected = pd.Series([2, 3])
          tm.assert_series_equal(result, expected)
      
          result = ser.loc[[3, 4]]
          tm.assert_series_equal(result, expected)
      

    在这种情况下,测试位置应该基于 潜在的 方法正在测试中。或者在错误修复测试的情况下,实际错误的位置。所以在这个例子中,我们知道 Series.__getitem__ 呼叫 Series.loc.__getitem__ ,所以这就是 真的 对…的测试 loc.__getitem__ 。所以这项测试属于 tests.indexing.test_loc

  6. 您的测试是DataFrame方法还是Series方法?

    1. 这种方法是一种标绘方法吗?此测试可能属于以下某一项:

      • tests.plotting

    2. 该方法是IO方法吗?此测试可能属于以下某一项:

      • tests.io

    3. 否则,此测试可能属于以下某一项:

      • tests.series.methods.test_mymethod

      • tests.frame.methods.test_mymethod

        备注

        如果可以在DataFrame/Series之间使用 frame_or_series 固定装置,按照惯例,它放在 tests.frame 文件。

  7. 您测试的是Index方法,而不是依赖于Series/DataFrame吗?此测试可能属于以下某一项:

    • tests.indexes

  1. 您的测试对象是Pandas提供的ExtensionArray吗 (CategoricalDatetimeArrayTimedeltaArrayPeriodArrayIntervalArrayPandasArrayFloatArrayBoolArrayStringArray )?此测试可能属于以下某一项:

    • tests.arrays

  2. 你的考试是不是 all 扩展数组子类(“EA接口”)?此测试可能属于以下某一项:

    • tests.extension