Best Python code snippet using tavern
DataAnalysis.py
Source:DataAnalysis.py
...50 a = DataCollector(os.getcwd() + "test/", data_name_list=["d1", "d2", "d3"], data_length_when_save=200)51 for i in range(2000):52 a.add_data([[1, 2], [1, 2, 3], [1, 2, 3, 4]])53 @staticmethod54 def test_load_one():55 a = np.load(os.getcwd() + "test/d3_1800.npy")56 print(a)57 print(a.shape)58class DataAnalysis():59 @staticmethod60 def plot_hist_on_different_ylabel(x, y, kwargs_for_ax=None, xlim=None):61 '''62 ç»å¶ä¸åy labelä¸çxçåå¸,ä¼å
æ ¹æ®yè¿æ»¤x,è¿æ»¤çæ¯ç»xä½ç´æ¹å¾63 :param x: æµ®ç¹æ°åé64 :param y: æ´æ°åé,代表label65 :return:66 '''67 assert isinstance(x, np.ndarray)68 assert isinstance(y, np.ndarray)69 y = y.astype(np.int8)70 assert x.shape[0] == y.shape[0]71 labels = list(set(y))72 label_to_x_dict = {}73 for label in labels:74 # éåºlabelåæ¯ä¸ªlabelç¸åçx,ä¹å°±æ¯group by label75 index = np.argwhere(label == y)76 filted_x = x[index]77 label_to_x_dict[label] = filted_x78 n_ax = len(labels)79 # å¦ælabel大äº9,å°±3å,å°äº9就两å80 if n_ax >= 9:81 n_cols = 382 else:83 n_cols = 284 n_rows = 085 while n_rows * n_cols < n_ax:86 n_rows += 187 fig, ax_list = plt.subplots(nrows=n_rows, ncols=n_cols)88 ax_list = ax_list.flatten()89 for i in range(n_ax):90 x = label_to_x_dict[labels[i]]91 mean = np.mean(x)92 std = np.std(x)93 if kwargs_for_ax is None:94 ax_list[i].hist(x, )95 else:96 ax_list[i].hist(x, **kwargs_for_ax)97 mean = "%.4f" % mean98 std = "%.4f" % std99 ax_list[i].set_title(str(labels[i]) + " mean: %s, std: %s" % (mean, std))100 if xlim is not None:101 ax_list[i].set_xlim(*xlim)102 fig.tight_layout()103 return plt104 @staticmethod105 def test_plot_hist_on_different_ylabel():106 DataAnalysis.plot_hist_on_different_ylabel(107 x=np.array([1, 2, 3, 4, 5, 6, 7, 8]),108 y=np.array([1, 2, 3, 1, 2, 3, 1, 1])109 ).show()110if __name__ == '__main__':111 # DataCollector.test_save()112 # DataCollector.test_load_one()...
test_database.py
Source:test_database.py
...23 def test_load_all(self):24 database = Database(':memory:')25 result = database.load_all('SELECT * FROM habits', [])26 self.assertEqual(5, len(result))27 def test_load_one(self):28 database = Database(':memory:')29 result = database.load_one('SELECT rowid FROM habits WHERE rowid=?', [1])...
test_yahoo_events.py
Source:test_yahoo_events.py
...5from pxtrade.events.yahoo import (6 load_yahoo_prices,7 YahooAssetLoader,8)9def test_load_one():10 with pytest.raises(NotImplementedError):11 load_yahoo_prices(None) # not a supported type12def test_loader():13 reset()14 with pytest.raises(TypeError):15 # requires a backtest object16 YahooAssetLoader(None, None)17 class MyStrategy(Strategy):18 def generate_trades(self):19 return None20 stock = Stock("AAPL")21 stock.yahoo_ticker = 12322 backtest = Backtest(MyStrategy())23 # yahoo_ticker for stock must be None or string...
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!!