How to use test_category method in tappy

Best Python code snippet using tappy_python

process_json_data_unittest.py

Source:process_json_data_unittest.py Github

copy

Full Screen

1# Copyright (C) 2014 Google Inc. All rights reserved.2#3# Redistribution and use in source and binary forms, with or without4# modification, are permitted provided that the following conditions are5# met:6#7# * Redistributions of source code must retain the above copyright8# notice, this list of conditions and the following disclaimer.9# * Redistributions in binary form must reproduce the above10# copyright notice, this list of conditions and the following disclaimer11# in the documentation and/or other materials provided with the12# distribution.13# * Neither the name of Google Inc. nor the names of its14# contributors may be used to endorse or promote products derived from15# this software without specific prior written permission.16#17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28import unittest29from webkitpy.layout_tests.generate_results_dashboard import ProcessJsonData30class ProcessJsonDataTester(unittest.TestCase):31 def test_check_failing_results(self):32 valid_json_data = {33 'tests': {34 'test_category': {35 'test_sub_category': {36 'test_name': {37 'test.html': {'expected': 'PASS', 'actual': 'TEXT', 'is_unexpected': True}38 }39 }40 }41 }42 }43 valid_json_data_1 = {44 'tests': {45 'test_category': {46 'test_sub_category': {47 'test_name': {48 'test.html': {'expected': 'TEXT', 'actual': 'TEXT', 'is_unexpected': True}49 }50 }51 }52 }53 }54 valid_json_data_2 = {55 'tests': {56 'test_category': {57 'test_sub_category': {58 'test_name_2': {59 'test_2.html': {'expected': 'PASS', 'actual': 'TEXT', 'is_unexpected': True}60 },61 'test_name': {62 'test.html': {'expected': 'TEXT', 'actual': 'TEXT', 'is_unexpected': True}63 }64 }65 }66 }67 }68 expected_result = {69 'tests': {70 'test_category': {71 'test_sub_category': {72 'test_name': {73 'test.html': {'archived_results': ['TEXT', 'PASS']}74 }75 }76 }77 }78 }79 process_json_data = ProcessJsonData(valid_json_data, [valid_json_data_1], [valid_json_data_2])80 actual_result = process_json_data.generate_archived_result()81 self.assertEqual(expected_result, actual_result)82 def test_check_full_results(self):83 valid_json_data = {84 'tests': {85 'test_category': {86 'test_sub_category': {87 'test_name_2': {88 'test_2.html': {'expected': 'PASS', 'actual': 'TEXT', 'is_unexpected': True}89 }90 }91 }92 }93 }94 valid_json_data_1 = {95 'tests': {96 'test_category': {97 'test_sub_category': {98 'test_name': {99 'test.html': {'expected': 'TEXT', 'actual': 'TEXT', 'is_unexpected': True}100 }101 }102 }103 }104 }105 valid_json_data_2 = {106 'tests': {107 'test_category': {108 'test_sub_category': {109 'test_name_2': {110 'test_2.html': {'expected': 'PASS', 'actual': 'TEXT', 'is_unexpected': True}111 },112 'test_name': {113 'test.html': {'expected': 'TEXT', 'actual': 'TEXT', 'is_unexpected': True}114 }115 }116 }117 }118 }119 expected_result = {120 'tests': {121 'test_category': {122 'test_sub_category': {123 'test_name_2': {124 'test_2.html': {'archived_results': ['TEXT', 'TEXT']}125 }126 }127 }128 }129 }130 process_json_data = ProcessJsonData(valid_json_data, [valid_json_data_1], [valid_json_data_2])131 actual_result = process_json_data.generate_archived_result()132 self.assertEqual(expected_result, actual_result)133 def test_null_check(self):134 valid_json_data = {135 'tests': {136 'test_category': {137 'test_sub_category': {138 'test_name': {139 'test.html': {'expected': 'PASS', 'actual': 'TEXT', 'is_unexpected': True}140 }141 }142 }143 }144 }145 expected_result = {146 'tests': {147 'test_category': {148 'test_sub_category': {149 'test_name': {150 'test.html': {'archived_results': ['TEXT']}}151 }152 }153 }154 }155 process_json_data = ProcessJsonData(valid_json_data, [], [])156 actual_result = process_json_data.generate_archived_result()...

Full Screen

Full Screen

test_category.py

Source:test_category.py Github

copy

Full Screen

1import unittest2from faker import Faker3from FlaskProject import create_app, db, TestCategory, FlaskProjectLogException4from FlaskProject.general import Status5from FlaskProject.controllers.test_category_controller.controller import \6 TestCategoryController7class TestTestCategoryController(unittest.TestCase):8 """9 This class is for testing TestCategoryController10 """11 def setUp(self):12 """13 Method for setUp TestCategoryController test module14 :return: OK or ERROR15 """16 self.app = create_app('development')17 self.app.testing = True18 self.client = self.app.test_client()19 self.ctx = self.app.app_context()20 self.ctx.push()21 self.faker = Faker()22 self.test_category_controller = TestCategoryController(23 test_category=TestCategory(24 name=self.faker.name()25 ))26 def test_create(self):27 """28 Method for testing creation of categories29 :return: OK or ERROR30 """31 status_insert = self.test_category_controller.create()32 self.assertEqual(33 Status.status_successfully_inserted().__dict__, status_insert)34 self.assertIsNotNone(self.test_category_controller.test_category.id)35 def test_create_already_exist(self):36 """37 Method for testing creation of categories when name is already taken38 :return: OK or ERROR39 """40 self.test_category_controller.create()41 with self.assertRaises(FlaskProjectLogException):42 self.test_category_controller.create()43 def test_alter(self):44 """45 Method for testing categories updates46 :return: OK or ERROR47 """48 self.test_category_controller.create()49 name = self.faker.name()50 self.test_category_controller.test_category.name = name51 result = self.test_category_controller.alter()52 self.assertEqual(Status.status_update_success().__dict__,53 result)54 self.assertEqual(name, self.test_category_controller.test_category.name)55 def test_inactivate(self):56 """57 Method for testing categories inactivate58 :return: OK OR ERROR59 """60 self.test_category_controller.create()61 result = self.test_category_controller.inactivate()62 self.assertEqual(Status.status_successfully_processed().__dict__,63 result)64 self.assertEqual(TestCategory.STATUSES['inactive'],65 self.test_category_controller.test_category.status)66 def test_activate(self):67 """68 Method for testing categories activate69 :return: OK OR ERROR70 """71 self.test_category_controller.create()72 result = self.test_category_controller.activate()73 self.assertEqual(Status.status_successfully_processed().__dict__,74 result)75 self.assertEqual(TestCategory.STATUSES['active'],76 self.test_category_controller.test_category.status)77 def test_get_one(self):78 """79 Method for testing get one category by identifier80 :return: OK OR ERROR81 """82 self.test_category_controller.create()83 result = TestCategoryController.get_one(84 self.test_category_controller.test_category.id)85 self.assertEqual(str(self.test_category_controller.test_category.id),86 str(result.test_category.id))87 def test_list_autocomplete(self):88 """89 Method for testing categories autocomplete90 :return: OK OR ERROR91 """92 self.test_category_controller.create()93 result = TestCategoryController.list_autocomplete(94 self.test_category_controller.test_category.name)95 self.assertEqual(list, type(result))96 self.assertIn(str(self.test_category_controller.test_category.id),97 [d['id'] for d in result])98 def test_get_list_pagination(self):99 """"100 Method for testing get list of all categories with pagination101 :return: OK or Error102 """103 self.test_category_controller.create()104 result = TestCategoryController.get_list_pagination(105 start=0, limit=10,106 name=self.test_category_controller.test_category.name)107 self.assertEqual(108 Status.status_successfully_processed().__dict__, result['status'])109 self.assertEqual(110 int, type(result['total']))111 self.assertEqual(112 list, type(result['data']))113 self.assertIn(str(self.test_category_controller.test_category.id),114 [d['id'] for d in result['data']])115 def tearDown(self):116 """117 Method for clean up data118 :return: OK or ERROR119 """120 TestCategory.query.filter(121 TestCategory.id ==122 self.test_category_controller.test_category.id).delete()123 db.session.commit()124if __name__ == '__main__':...

Full Screen

Full Screen

Q10SVNNB.py

Source:Q10SVNNB.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2"""3Created on Sun Mar 11 18:30:09 20184@author: chaoran5"""6from sklearn.datasets import fetch_20newsgroups7from sklearn.feature_extraction.text import CountVectorizer8from sklearn.feature_extraction.text import TfidfTransformer9from sklearn.model_selection import train_test_split10from sklearn.naive_bayes import MultinomialNB11from sklearn.svm import LinearSVC12from sklearn.svm import SVC13from sklearn.linear_model import SGDClassifier14from sklearn.pipeline import Pipeline15from sklearn import metrics16import numpy as np17# NaiveBayes algorithm18def NB(categories):19 #get the data from 4 folder20 all_four = fetch_20newsgroups(subset='all',categories=categories, shuffle=True, random_state=42)21 #split the data to training data and test data 22 train_data, test_data, train_category, test_category = train_test_split(all_four.data, all_four.target, test_size = 0.3) 23 #unigram24 #pipeline for text feature extraction and evaluation 25 #tokenizer => transformer => MultinomialNB classifier26 text_clf = Pipeline([('vect', CountVectorizer( analyzer = 'word',ngram_range = (1,1), stop_words='english')),('tfidf', TfidfTransformer()),('clf', MultinomialNB(alpha=.01))])27 text_clf = text_clf.fit(train_data, train_category)28 #evaluate on test set29 predicted = text_clf.predict(test_data)30 print("************************* Naive Bayes Model *************************")31 print("Newsgroup Categories : ", categories )32 print("Unigram Accuracy : {}% \n".format(np.mean(predicted == test_category)*100))33 print(metrics.classification_report(test_category, predicted, target_names=categories))34 print("Unigram Confusion Matrix : \n", metrics.confusion_matrix(test_category, predicted))35 print("\n")36 #bigram37 #pipeline for text feature extraction and evaluation 38 #tokenizer => transformer => MultinomialNB classifier 39 bigram_clf = Pipeline([('vect', CountVectorizer( analyzer = 'word',ngram_range = (2,2), stop_words='english')),('tfidf', TfidfTransformer()),('clf', MultinomialNB(alpha=.01))])40 bigram_clf = bigram_clf.fit(train_data, train_category) 41 #evaluate on test set 42 predicted = bigram_clf.predict(test_data)43 print("Bigram Accuracy : {}% \n".format(np.mean(predicted == test_category)*100))44 print(metrics.classification_report(test_category, predicted, target_names=categories))45 print("Bigram Confusion Matrix : \n", metrics.confusion_matrix(test_category, predicted)) 46 47 48# SVM algorithm49def SVM(categories):50 #get the data from 4 folder51 all_four = fetch_20newsgroups(subset='all',categories=categories, shuffle=True, random_state=42)52 #split the data to training data and test data 53 train_data, test_data, train_category, test_category = train_test_split(all_four.data, all_four.target, test_size = 0.3)54 #unigram55 #pipeline for text feature extraction and evaluation 56 #tokenizer => transformer => MultinomialNB classifier57 #LinearSVC()58 unigram_clf = Pipeline([('vect', CountVectorizer( analyzer = 'word',ngram_range = (1,1), stop_words='english')),('tfidf', TfidfTransformer()),('clf', LinearSVC())])59 unigram_clf = unigram_clf.fit(train_data, train_category) 60 #evaluate on test set 61 predicted = unigram_clf.predict(test_data)62 print("************************* SVM Model *************************")63 print("Newsgroup Categories : ", categories )64 print("Unigram Accuracy : {}% \n".format(np.mean(predicted == test_category)*100))65 print(metrics.classification_report(test_category, predicted, target_names=categories))66 print("Unigram Confusion Matrix : \n", metrics.confusion_matrix(test_category, predicted))67 print("\n")68 #bigram 69 #pipeline for text feature extraction and evaluation 70 #tokenizer => transformer => MultinomialNB classifier71 #SGDClassifier(loss='hinge')72 bigram_clf = Pipeline([('vect', CountVectorizer( analyzer = 'word',ngram_range = (2,2), stop_words='english')),('tfidf', TfidfTransformer()),('clf', LinearSVC())])73 bigram_clf = bigram_clf.fit(train_data, train_category) 74 #evaluate on test set 75 predicted = bigram_clf.predict(test_data)76 print("Bigram Accuracy : {}% \n".format(np.mean(predicted == test_category)*100))77 print(metrics.classification_report(test_category, predicted, target_names=categories))78 print("Bigram Confusion Matrix : \n", metrics.confusion_matrix(test_category, predicted)) 79 80# selected categories81categories = ['alt.atheism','talk.religion.misc','comp.graphics','sci.space']82NB(categories)...

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