How to use test_dates method in assertpy

Best Python code snippet using assertpy_python

test_booking.py

Source:test_booking.py Github

copy

Full Screen

1from datetime import date2import pytest3from hotel_california.domain.models import BookingDate, Room, Order4from hotel_california.service_layer.exceptions import RoomNonFree5from hotel_california.service_layer.service.hotel import Status, RoomManager6@pytest.fixture7def manager():8 return RoomManager(9 rooms={10 1: Room(11 number=1,12 capacity=1,13 price=100,14 orders=[15 Order(16 identity=1,17 dates=[18 BookingDate(date=date(2000, 1, 1), status=int(Status.ARRIVAL)),19 BookingDate(date=date(2000, 1, 7), status=int(Status.DEPARTURE)),20 ]21 ),22 Order(23 identity=2,24 dates=[25 BookingDate(date=date(2000, 1, 14), status=int(Status.ARRIVAL)),26 BookingDate(date=date(2000, 1, 23), status=int(Status.DEPARTURE)),27 ]28 )29 ]30 )}31 )32def test_check_free_room(manager):33 test_dates = (34 BookingDate(date=date(2000, 1, 8), status=int(Status.ARRIVAL)),35 BookingDate(date=date(2000, 1, 10), status=int(Status.DEPARTURE)),36 )37 manager.check_room(1, test_dates)38def test_check_free_room1(manager):39 # случай с выездом и заездом в один день40 test_dates = (41 BookingDate(date=date(2000, 1, 7), status=int(Status.ARRIVAL)),42 BookingDate(date=date(2000, 1, 10), status=int(Status.DEPARTURE)),43 )44 manager.check_room(1, test_dates)45def test_check_free_room2(manager):46 # случай с выездом и заездом в один день(и выезд в день заезда следующего клиента)47 test_dates = (48 BookingDate(date=date(2000, 1, 7), status=int(Status.ARRIVAL)),49 BookingDate(date=date(2000, 1, 10), status=int(Status.DEPARTURE)),50 )51 manager.check_room(1, test_dates)52def test_check_free_room_raise(manager):53 # пересечение заезда54 test_dates = (55 BookingDate(date=date(2000, 1, 6), status=int(Status.ARRIVAL)),56 BookingDate(date=date(2000, 1, 10), status=int(Status.DEPARTURE)),57 )58 with pytest.raises(RoomNonFree):59 manager.check_room(1, test_dates)60def test_check_free_room_raise1(manager):61 # пересечение выезда62 test_dates = (63 BookingDate(date=date(2000, 1, 8), status=int(Status.ARRIVAL)),64 BookingDate(date=date(2000, 1, 15), status=int(Status.DEPARTURE)),65 )66 with pytest.raises(RoomNonFree):67 manager.check_room(1, test_dates)68def test_check_free_room_raise2(manager):69 # пересечение заезда и выезда70 test_dates = (71 BookingDate(date=date(2000, 1, 2), status=int(Status.ARRIVAL)),72 BookingDate(date=date(2000, 1, 5), status=int(Status.DEPARTURE)),73 )74 with pytest.raises(RoomNonFree):...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1from NIPA.datatype import Country, PreprocessInfo, DatasetInfo2from NIPA.io import load_links, save_setting, load_dataset, save_parameters, save_results3from NIPA.loader import DataLoader4from NIPA.nipa import train_nipa, predict5from NIPA.util import get_predict_period_from_dataset6import argparse7import pandas as pd8def get_args():9 parser = argparse.ArgumentParser(description='test')10 parser.add_argument(11 "--country", type=str, default='italy',12 choices=['italy', 'india', 'us', 'china'],13 help="Country name"14 )15 parser.add_argument(16 "--standardization", type=bool, default=False,17 help="standardization"18 )19 parser.add_argument(20 "--x_frames", type=int, default=15,21 help="Number of x frames for generating dataset"22 )23 parser.add_argument(24 "--y_frames", type=int, default=3,25 help="Number of x frames for generating dataset"26 )27 args = parser.parse_args()28 return args29def main(args):30 country = Country[args.country.upper()]31 link_df = load_links(country)32 sird_info = PreprocessInfo(country=country, start=link_df['start_date'], end=link_df['end_date'],33 increase=True, daily=True, remove_zero=True,34 smoothing=True, window=5, divide=True)35 save_setting(sird_info, 'sird_info')36 dataset = load_dataset(country, sird_info.get_hash())37 predict_dates = get_predict_period_from_dataset(dataset, args.x_frames, args.y_frames)38 data_info = DatasetInfo(x_frames=args.x_frames, y_frames=args.y_frames,39 test_start=predict_dates[0], test_end=predict_dates[-1])40 save_setting(data_info, 'data_info')41 loader = DataLoader(data_info, dataset)42 train_I, test_I, test_dates = loader[0]43 regions = train_I.index.tolist()44 I_df = pd.DataFrame(index=regions, columns=predict_dates)45 I_df.index.name = 'regions'46 R_df = pd.DataFrame(index=regions, columns=predict_dates)47 R_df.index.name = 'regions'48 for i in range(len(loader)):49 train_I, test_I, test_dates = loader[i]50 dataset.update({'train': train_I})51 dataset.update({'test': test_I})52 print(f'Predicting {test_dates[0]} to {test_dates[-1]} ===============================')53 curing_df, B_df = train_nipa(dataset, args.standardization)54 save_parameters(country, sird_info, data_info, test_dates[0], curing_df, B_df)55 pred_I_df, pred_R_df = predict(dataset, curing_df, B_df)56 I_df.loc[:, test_dates[0]] = pred_I_df.loc[:, test_dates[0]]57 R_df.loc[:, test_dates[0]] = pred_R_df.loc[:, test_dates[0]]58 save_results(country, sird_info, data_info, test_dates[0], pred_I_df, pred_R_df)59 save_results(country, sird_info, data_info, None, I_df, R_df)60if __name__ == '__main__':61 args = get_args()...

Full Screen

Full Screen

rtn_opt_dates.py

Source:rtn_opt_dates.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2from datetime import datetime, timedelta3def rtn_dates(beg, end=None, using_weekend=False, rtn_string=True):4 """5 :param beg: Date String, e.g. 20170901, 2017-09-016 :param end: Date String, e.g. 20170901, 2017-09-01, if not specified, using current date7 :param using_weekend:8 :param rtn_string: (indicate whether the returned value is a string or a python date object9 :return:10 Example:11 rtn_dates('20170801', '20170805', using_weekend=True, rtn_string=True)12 =['20170801', '20170802', '20170803', '20170804', '20170805']13 """14 beg = beg.replace("-", "")15 beg_date = datetime.strptime(beg, "%Y%m%d").date()16 if isinstance(end, str) and len(end):17 end = end.replace("-", "")18 end_date = datetime.strptime(end, "%Y%m%d").date()19 else:20 end_date = datetime.now().date()21 test_dates = []22 while beg_date <= end_date:23 week_day = beg_date.weekday() + 1 # .weekday() : Monday: 0, Sunday: 624 if (week_day != 6 and week_day != 7) or using_weekend:25 test_dates.append(beg_date)26 beg_date += timedelta(days=1)27 if rtn_string:28 test_dates = list(map(lambda x: x.strftime("%Y%m%d"), test_dates))29 return test_dates30def _rtn_opt_dates(d, using_weekend=False, rtn_string=True):31 """32 :param d: date string: e.g. 20170901-20170920,20171001,2017102033 :param using_weekend:34 :param rtn_string:35 :return:36 """37 test_dates = []38 ds = d.replace(' ', '').split(',')39 for dd in ds:40 if '-' in dd:41 ddd = dd.split('-')42 test_dates += rtn_dates(ddd[0], ddd[1], using_weekend, False)43 pass44 else:45 ddd = datetime.strptime(dd, "%Y%m%d").date()46 week_day = ddd.weekday() + 147 if (week_day != 6 and week_day != 7) or using_weekend:48 test_dates.append(ddd)49 if rtn_string:50 test_dates = list(map(lambda x: x.strftime("%Y%m%d"), test_dates))51 return test_dates52def rtn_opt_dates(d, using_weekend=False, rtn_string=True):53 """54 with exclusive feature55 :param d: date string: e.g. 20170901-20170920,20171001,20171020\2017090556 :param using_weekend:57 :param rtn_string:58 :return:59 """60 if '\\' in d:61 dd = d.split('\\')62 dd1 = _rtn_opt_dates(dd[0], using_weekend, rtn_string)63 dd2 = _rtn_opt_dates(dd[1], using_weekend, rtn_string)64 return sorted(list(set(dd1) - set(dd2)))65 else:66 return _rtn_opt_dates(d, using_weekend, rtn_string)67if __name__ == "__main__":68 print(rtn_opt_dates('20170521-20170531,20170603-20170701, 20170716'))69 print(rtn_opt_dates('20170521-20170531,20170603-20170701, 20170716\\20170613'))...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run assertpy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful