def test__sample_children(self): """Test sample children""" # Setup sampler = Mock(spec=Sampler) sampler.metadata.get_children.return_value = [ 'child A', 'child B', 'child C' ] # Run sampled = {'test': pd.DataFrame({'field': [11, 22, 33]})} Sampler._sample_children(sampler, 'test', sampled) # Asserts sampler.metadata.get_children.assert_called_once_with('test') expected_calls = [ [ 'child A', 'test', pd.Series([11], index=['field'], name=0), sampled ], [ 'child A', 'test', pd.Series([22], index=['field'], name=1), sampled ], [ 'child A', 'test', pd.Series([33], index=['field'], name=2), sampled ], [ 'child B', 'test', pd.Series([11], index=['field'], name=0), sampled ], [ 'child B', 'test', pd.Series([22], index=['field'], name=1), sampled ], [ 'child B', 'test', pd.Series([33], index=['field'], name=2), sampled ], [ 'child C', 'test', pd.Series([11], index=['field'], name=0), sampled ], [ 'child C', 'test', pd.Series([22], index=['field'], name=1), sampled ], [ 'child C', 'test', pd.Series([33], index=['field'], name=2), sampled ], ] actual_calls = sampler._sample_table.call_args_list for result_call, expected_call in zip(actual_calls, expected_calls): assert result_call[0][0] == expected_call[0] assert result_call[0][1] == expected_call[1] assert result_call[0][3] == expected_call[3] pd.testing.assert_series_equal(result_call[0][2], expected_call[2])
def test__sample_children(self): """Sample children""" # Setup dn_mock = Mock() dn_mock.get_children.return_value = ['aaa', 'bbb', 'ccc'] sample_mock = Mock() # Run sampler_mock = Mock() sampler_mock.dn = dn_mock sampler_mock._sample = sample_mock table_name = 'DEMO' sampled = {'DEMO': pd.DataFrame({'foo': [0, 1]})} Sampler._sample_children(sampler_mock, table_name, sampled) # Asserts exp_sampled = {'DEMO': pd.DataFrame({'foo': [0, 1]})} exp_sample_arguments = [ ('aaa', 'DEMO', pd.Series({'foo': 0}, name=0), exp_sampled), ('aaa', 'DEMO', pd.Series({'foo': 1}, name=1), exp_sampled), ('bbb', 'DEMO', pd.Series({'foo': 0}, name=0), exp_sampled), ('bbb', 'DEMO', pd.Series({'foo': 1}, name=1), exp_sampled), ('ccc', 'DEMO', pd.Series({'foo': 0}, name=0), exp_sampled), ('ccc', 'DEMO', pd.Series({'foo': 1}, name=1), exp_sampled) ] dn_mock.get_children.assert_called_once_with('DEMO') assert sample_mock.call_count == 6 for called, expected in zip(sample_mock.call_args_list, exp_sample_arguments): assert called[0][0] == expected[0] assert called[0][1] == expected[1] pd.testing.assert_series_equal(called[0][2], expected[2]) pd.testing.assert_frame_equal(called[0][3]['DEMO'], expected[3]['DEMO'])