Best Python code snippet using tox_python
test_loc.py
Source:test_loc.py
1import numpy as np2import pytest3import pandas as pd4from pandas import Series, Timestamp5from pandas.util.testing import assert_series_equal6@pytest.mark.parametrize("val,expected", [(2 ** 63 - 1, 3), (2 ** 63, 4)])7def test_loc_uint64(val, expected):8 # see gh-193999 s = Series({2 ** 63 - 1: 3, 2 ** 63: 4})10 assert s.loc[val] == expected11def test_loc_getitem(test_data):12 inds = test_data.series.index[[3, 4, 7]]13 assert_series_equal(test_data.series.loc[inds], test_data.series.reindex(inds))14 assert_series_equal(test_data.series.iloc[5::2], test_data.series[5::2])15 # slice with indices16 d1, d2 = test_data.ts.index[[5, 15]]17 result = test_data.ts.loc[d1:d2]18 expected = test_data.ts.truncate(d1, d2)19 assert_series_equal(result, expected)20 # boolean21 mask = test_data.series > test_data.series.median()22 assert_series_equal(test_data.series.loc[mask], test_data.series[mask])23 # ask for index value24 assert test_data.ts.loc[d1] == test_data.ts[d1]25 assert test_data.ts.loc[d2] == test_data.ts[d2]26def test_loc_getitem_not_monotonic(test_data):27 d1, d2 = test_data.ts.index[[5, 15]]28 ts2 = test_data.ts[::2][[1, 2, 0]]29 msg = r"Timestamp\('2000-01-10 00:00:00'\)"30 with pytest.raises(KeyError, match=msg):31 ts2.loc[d1:d2]32 with pytest.raises(KeyError, match=msg):33 ts2.loc[d1:d2] = 034def test_loc_getitem_setitem_integer_slice_keyerrors():35 s = Series(np.random.randn(10), index=list(range(0, 20, 2)))36 # this is OK37 cp = s.copy()38 cp.iloc[4:10] = 039 assert (cp.iloc[4:10] == 0).all()40 # so is this41 cp = s.copy()42 cp.iloc[3:11] = 043 assert (cp.iloc[3:11] == 0).values.all()44 result = s.iloc[2:6]45 result2 = s.loc[3:11]46 expected = s.reindex([4, 6, 8, 10])47 assert_series_equal(result, expected)48 assert_series_equal(result2, expected)49 # non-monotonic, raise KeyError50 s2 = s.iloc[list(range(5)) + list(range(9, 4, -1))]51 with pytest.raises(KeyError, match=r"^3$"):52 s2.loc[3:11]53 with pytest.raises(KeyError, match=r"^3$"):54 s2.loc[3:11] = 055def test_loc_getitem_iterator(test_data):56 idx = iter(test_data.series.index[:10])57 result = test_data.series.loc[idx]58 assert_series_equal(result, test_data.series[:10])59def test_loc_setitem_boolean(test_data):60 mask = test_data.series > test_data.series.median()61 result = test_data.series.copy()62 result.loc[mask] = 063 expected = test_data.series64 expected[mask] = 065 assert_series_equal(result, expected)66def test_loc_setitem_corner(test_data):67 inds = list(test_data.series.index[[5, 8, 12]])68 test_data.series.loc[inds] = 569 msg = r"\['foo'\] not in index"70 with pytest.raises(KeyError, match=msg):71 test_data.series.loc[inds + ["foo"]] = 572def test_basic_setitem_with_labels(test_data):73 indices = test_data.ts.index[[5, 10, 15]]74 cp = test_data.ts.copy()75 exp = test_data.ts.copy()76 cp[indices] = 077 exp.loc[indices] = 078 assert_series_equal(cp, exp)79 cp = test_data.ts.copy()80 exp = test_data.ts.copy()81 cp[indices[0] : indices[2]] = 082 exp.loc[indices[0] : indices[2]] = 083 assert_series_equal(cp, exp)84 # integer indexes, be careful85 s = Series(np.random.randn(10), index=list(range(0, 20, 2)))86 inds = [0, 4, 6]87 arr_inds = np.array([0, 4, 6])88 cp = s.copy()89 exp = s.copy()90 s[inds] = 091 s.loc[inds] = 092 assert_series_equal(cp, exp)93 cp = s.copy()94 exp = s.copy()95 s[arr_inds] = 096 s.loc[arr_inds] = 097 assert_series_equal(cp, exp)98 inds_notfound = [0, 4, 5, 6]99 arr_inds_notfound = np.array([0, 4, 5, 6])100 msg = r"\[5\] not contained in the index"101 with pytest.raises(ValueError, match=msg):102 s[inds_notfound] = 0103 with pytest.raises(Exception, match=msg):104 s[arr_inds_notfound] = 0105 # GH12089106 # with tz for values107 s = Series(108 pd.date_range("2011-01-01", periods=3, tz="US/Eastern"), index=["a", "b", "c"]109 )110 s2 = s.copy()111 expected = Timestamp("2011-01-03", tz="US/Eastern")112 s2.loc["a"] = expected113 result = s2.loc["a"]114 assert result == expected115 s2 = s.copy()116 s2.iloc[0] = expected117 result = s2.iloc[0]118 assert result == expected119 s2 = s.copy()120 s2["a"] = expected121 result = s2["a"]...
test_overview.py
Source:test_overview.py
1# -*- coding: UTF-8 -*-2"""3@File ï¼test_overview.py4@Author ï¼taofangpeng5@Date ï¼2022/10/8 10:30 6"""7import pytest8from api.overview import overview9from common.data_load import get_yaml_data10from common.logger import logger111213class TestOverview:1415 @pytest.mark.parametrize('test_data', get_yaml_data('test_overview.yaml', 'count_collection_num'))16 def test_count_collection_num(self, test_data):17 logger.info("éåæ»æ°éæµè¯æ°æ®ä¸ºï¼{}".format(test_data))18 res = overview.count_collection_num()19 assert res['code'] == test_data['code']20 count_interface = res['data']21 count_sql = test_data['sql_data'][0][0]['count']22 logger.info(23 "é¦é¡µoverviewç»è®¡éåæ»æ°æ¥å£æµè¯æ°æ®ä¸ºï¼æ°æ®åºæ¥è¯¢ï¼æ¥å£è¿åï¼ï¼[{}ï¼{}]".format(count_sql, count_interface))24 assert count_sql == count_interface2526 @pytest.mark.parametrize('test_data', get_yaml_data('test_overview.yaml', 'market_cap_and_volume'))27 def test_market_cap_and_volume(self, test_data):28 logger.info("æ»å¸å¼åæ»äº¤æéæµè¯æ°æ®ä¸ºï¼{}".format(test_data))29 res = overview.market_cap_and_volume_app(30 params={"timeRange": test_data['timeRange']} if 'timeRange' in test_data else '')31 if 'code' in test_data:32 assert test_data['code'] == res['code']33 else:34 assert test_data['status'] == res['status']3536 @pytest.mark.parametrize('test_data', get_yaml_data('test_overview.yaml', 'heat_map'))37 def test_heat_map(self, test_data):38 logger.info("çåå¾æµè¯æ°æ®ä¸ºï¼{}".format(test_data))39 params = {}40 if 'timeRange' in test_data:41 params['timeRange'] = test_data['timeRange']42 if 'dataNum' in test_data:43 params['dataNum'] = test_data['dataNum']44 res = overview.heat_map_app(params=params)45 if 'code' in test_data:46 assert test_data['code'] == res['code']47 else:48 assert test_data['status'] == res['status']49 if 'rise_list_len' in test_data:50 assert test_data['rise_list_len'] == len(res['data']['riseList'])51 assert test_data['fall_list_len'] == len(res['data']['fallList'])5253 @pytest.mark.parametrize('test_data', get_yaml_data('test_overview.yaml', 'top_ten'))54 def test_top_ten(self, test_data):55 logger.info("top tenæµè¯æ°æ®ä¸ºï¼{}".format(test_data))56 params = {}57 if 'timeRange' in test_data:58 params['timeRange'] = test_data['timeRange']59 if 'type' in test_data:60 params['type'] = test_data['type']61 res = overview.top_ten_app(params=params)62 if 'code' in test_data:63 assert test_data['code'] == res['code']64 else:65 assert test_data['status'] == res['status']66 if 'len_list' in test_data:67 for name in test_data['len_list_name'].split(','):68 assert test_data['len_list'] == len(res['data'][name])6970 @pytest.mark.parametrize('test_data', get_yaml_data('test_overview.yaml', 'ethereum'))71 def test_ethereum(self, test_data):72 logger.info("ethereumæµè¯æ°æ®ä¸ºï¼{}".format(test_data))73 params = {}74 if 'timeRange' in test_data:75 params['timeRange'] = test_data['timeRange']76 if 'type' in test_data:77 params['type'] = test_data['type']78 res = overview.ethereum_app(params=params)79 if 'code' in test_data:80 assert test_data['code'] == res['code']81 else:82 assert test_data['status'] == res['status']83 if 'len_list' in test_data:84 for name in test_data['len_list_name'].split(','):
...
test_bedtrace.py
Source:test_bedtrace.py
...9# |------------------| |--|10# C.bed11# |-| |-| |-| |-| |-|12def test_str_simple(test_data):13 assert str(Bed(test_data("bed/A.bed"))) == "A.bed"14def test_str_compound(test_data):15 c = minus(union(Bed(test_data("bed/B.bed")),16 Bed(test_data("bed/A.bed"))),17 Bed(test_data("bed/C.bed")))18 assert """minus19\tunion20\t\tB.bed21\t\tA.bed22\tC.bed""" == str(c)23def test_union(test_data):24 u = union(Bed(test_data("bed/A.bed")),25 Bed(test_data("bed/B.bed")))26 assert u.path is None27 u.compute()28 assert u.path is not None29 actual = Path(u.path).read_text().replace(test_data("bed/"), '')30 assert actual == """chr1 0 100 1_A.bed31chr1 150 500 1_A.bed|2_B.bed32chr1 600 750 1_A.bed|2_B.bed33"""34def test_intersect(test_data):35 i = intersect(Bed(test_data("bed/A.bed")), Bed(test_data("bed/B.bed")))36 assert i.path is None37 i.compute()38 assert i.path is not None39 assert Path(i.path).read_text() == ("chr1 150 500\n"40 "chr1 600 750\n")41def test_minus(test_data):42 m = minus(Bed(test_data("bed/A.bed")), Bed(test_data("bed/B.bed")))43 assert m.path is None44 m.compute()45 assert m.path is not None46 assert Path(m.path).read_text() == "chr1 0 100\n"47@pytest.mark.parametrize("files,expected_count", [48 (["A.bed"], 4),49 (["B.bed"], 2),50 (["C.bed"], 5),51 (["A.bed", "B.bed"], 3),52])53def test_count(test_data, files, expected_count):54 if len(files) == 1:55 bed = Bed(test_data("bed/" + files[0]))56 else:57 bed = union(*[Bed(test_data("bed/" + f)) for f in files])58 assert bed.count() == expected_count59def test_compare(test_data):60 c = compare(Bed(test_data("bed/A.bed")), Bed(test_data("bed/B.bed")))61 assert c.path is None62 c.compute()63 assert c.path is not None64 assert Path(c.cond1).read_text() == "chr1 0 100\n"65 assert Path(c.cond2).read_text() == ""66 assert Path(c.common).read_text() == ("chr1 150 500\n"67 "chr1 600 750\n")68def test_jaccard(test_data):69 u = jaccard(test_data("bed/A.bed"), test_data("bed/B.bed"))70 assert u == 1.0 / 3.071def test_jaccard_not_sorted(test_data):72 u = jaccard(test_data("bed/A.unsorted.bed"), test_data("bed/B.unsorted.bed"))73 assert u == 1.0 / 3.074def test_jaccard_self_intersections(test_data):75 u = jaccard(test_data("bed/E.bed"), test_data("bed/F.bed"))76 assert u == 35.0 / 72.077def test_save(test_data):78 assert union(Bed(test_data("bed/A.bed")),79 Bed(test_data("bed/B.bed"))).count() == 380def test_cat(test_data):81 u = Bed(test_data("bed/A.bed"))82 assert u.cat() == """chr1 0 10083chr1 200 30084chr1 400 50085chr1 600 700...
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!!