How to use _construct_test method in Testify

Best Python code snippet using Testify_python

test_env_context.py

Source:test_env_context.py Github

copy

Full Screen

...136 # __enter__() test137 if (_test_enter):138 self.conduct_tests(139 func=func,140 tests=_construct_test(_test_enter.get("answer", None)),141 )142 # __exit__() test143 if (_test_exit):144 self.conduct_tests(145 func=func,146 tests=_construct_test(_test_exit.get("answer", None)),147 )148 def test_EnvironmentContext(self):149 _old_environment = dict(os.environ)150 _test_envs = {151 "SAMPLE_ENVVAR1":"Testing Temporary System Variable 1",152 "SAMPLE_ENVVAR2":"Testing Temporary System Variable 2",153 "SAMPLE_ENVVAR3":"Testing Temporary System Variable 3",154 }155 _tests_enter = [156 {157 # These are args for the context manager, not the tests158 "args":{159 # Just update the variables160 "update":_test_envs,...

Full Screen

Full Screen

dataset.py

Source:dataset.py Github

copy

Full Screen

...32 df, self.num_users, self.num_items = self._load_data(file_path)33 self.pos_dict = self._construct_pos_dict(df)34 self.train_df, self.test_df = self._split_train_test(df)35 self.train_dict = self._construct_train(self.train_df)36 self.test_dict = self._construct_test(self.test_df)373839 def _load_data(self, file_path):40 df = pd.read_csv(file_path, sep=',', usecols=[0, 1])4142 # constructing index43 uiterator = count(0)44 udict = defaultdict(lambda: next(uiterator))45 [udict[user] for user in sorted(df['reviewerID'].tolist())]46 iiterator = count(0)47 idict = defaultdict(lambda: next(iiterator))48 [idict[item] for item in sorted(df['asin'].tolist())]4950 self.udict = udict51 self.idict = idict5253 df['uidx'] = df['reviewerID'].map(lambda x: udict[x])54 df['iidx'] = df['asin'].map(lambda x: idict[x])55 del df['reviewerID'], df['asin']56 print('Load %s data successfully with %d users, %d products and %d interactions.'57 %(self.name, len(udict), len(idict), df.shape[0]))5859 return df, len(udict), len(idict)606162 def _construct_pos_dict(self, df):63 # we can't build a negative dictionary cause it'll cost huge memory64 pos_dict = defaultdict(set)65 for user, item in zip(df['uidx'], df['iidx']):66 pos_dict[user].add(item)6768 return pos_dict697071 def _split_train_test(self, df):72 test_list = []73 print('Spliting data of train and test...')74 with Pool(self.args.processor_num) as pool:75 nargs = [(user, df, self.args.test_size) for user in range(self.num_users)]76 test_list = pool.map(self._split, nargs)7778 test_df = pd.concat(test_list)79 train_df = df.drop(test_df.index)8081 train_df = train_df.reset_index(drop=True)82 test_df = test_df.reset_index(drop=True)8384 train_df.to_csv(self.path+'/​%s_train_df.csv'% self.name, index=False)85 test_df.to_csv(self.path+'/​%s_test_df.csv'% self.name, index=False)8687 return train_df, test_df888990 def _construct_train(self, df):91 # It's desperate to use df to calculate... so slow!!!92 print('Adding negative data to train_df...')93 users = []94 items = []95 labels = []96 with Pool(self.args.processor_num) as pool:97 nargs = [(user, item, self.num_items, self.pos_dict, self.args.train_neg_num, True)98 for user, item in zip(df['uidx'], df['iidx'])]99 res_list = pool.map(self._add_negtive, nargs)100101 for (batch_users, batch_items, batch_labels) in res_list:102 users += batch_users103 items += batch_items104 labels += batch_labels105106 data_dict = {'user': users, 'item': items, 'label': labels}107 np.save(self.train_npy_path, data_dict)108109 return data_dict110111112 def _construct_test(self, df):113 print('Adding negative data to test_df...')114 users = []115 items = []116 labels = []117118 with Pool(self.args.processor_num) as pool:119 nargs = [(user, item, self.num_items, self.pos_dict, self.args.test_neg_num, False)120 for user, item in zip(df['uidx'], df['iidx'])]121 res_list = pool.map(self._add_negtive, nargs)122123 for batch_users, batch_items, batch_labels in res_list:124 users += batch_users125 items += batch_items126 labels += batch_labels ...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

24 Testing Scenarios you should not automate with Selenium

While there is a huge demand and need to run Selenium Test Automation, the experts always suggest not to automate every possible test. Exhaustive Testing is not possible, and Automating everything is not sustainable.

Best 13 Tools To Test JavaScript Code

Unit and functional testing are the prime ways of verifying the JavaScript code quality. However, a host of tools are available that can also check code before or during its execution in order to test its quality and adherence to coding standards. With each tool having its unique features and advantages contributing to its testing capabilities, you can use the tool that best suits your need for performing JavaScript testing.

Guide To Find Index Of Element In List with Python Selenium

In an ideal world, you can test your web application in the same test environment and return the same results every time. The reality can be difficult sometimes when you have flaky tests, which may be due to the complexity of the web elements you are trying to perform an action on your test case.

Difference Between Web vs Hybrid vs Native Apps

Native apps are developed specifically for one platform. Hence they are fast and deliver superior performance. They can be downloaded from various app stores and are not accessible through browsers.

How To Run Cypress Tests In Azure DevOps Pipeline

When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today don’t have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesn’t make life easier for users, they’ll leave for a better solution.

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 Testify 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