How to use test_tuples method in assertpy

Best Python code snippet using assertpy_python

test_graph_reference.py

Source:test_graph_reference.py Github

copy

Full Screen

1"""2A module to test functionality related to *using* the graph reference.3"""4from __future__ import absolute_import5import os6from pkg_resources import resource_string7from unittest import TestCase8from nose.plugins.attrib import attr9from requests.compat import json as _json10from plotly import graph_reference as gr11from plotly.api import v212from plotly.graph_reference import string_to_class_name, get_role13from plotly.tests.utils import PlotlyTestCase14FAKE_API_DOMAIN = 'https://api.am.not.here.ly'15class TestGraphReferenceCaching(PlotlyTestCase):16 @attr('slow')17 def test_default_schema_is_up_to_date(self):18 response = v2.plot_schema.retrieve('')19 schema = response.json()['schema']20 path = os.path.join('package_data', 'default-schema.json')21 s = resource_string('plotly', path).decode('utf-8')22 default_schema = _json.loads(s)23 msg = (24 'The default, hard-coded plot schema we ship with pip is out of '25 'sync with the prod plot schema!\n'26 'Run `make update_default_schema` to fix it!'27 )28 self.assertEqual(schema, default_schema, msg=msg)29class TestStringToClass(PlotlyTestCase):30 def test_capitalize_first_letter(self):31 object_names = ['marker', 'line', 'scatter']32 class_names = ['Marker', 'Line', 'Scatter']33 for object_name, class_name in zip(object_names, class_names):34 self.assertEqual(string_to_class_name(object_name), class_name)35 def test_capitalize_after_underscore(self):36 object_names = ['error_y', 'error_x']37 class_names = ['ErrorY', 'ErrorX']38 for object_name, class_name in zip(object_names, class_names):39 self.assertEqual(string_to_class_name(object_name), class_name)40class TestObjectNameToClassName(TestCase):41 def test_backwards_compat(self):42 # Old classes should still be shown to users.43 test_tuples = [44 ('angularaxis', 'AngularAxis'),45 ('annotation', 'Annotation'),46 ('annotations', 'Annotations'),47 ('area', 'Area'),48 ('colorbar', 'ColorBar'),49 ('contour', 'Contour'),50 ('contours', 'Contours'),51 ('data', 'Data'),52 ('error_x', 'ErrorX'),53 ('error_y', 'ErrorY'),54 ('error_z', 'ErrorZ'),55 ('figure', 'Figure'),56 ('font', 'Font'),57 ('layout', 'Layout'),58 ('legend', 'Legend'),59 ('margin', 'Margin'),60 ('marker', 'Marker'),61 ('radialaxis', 'RadialAxis'),62 ('scene', 'Scene'),63 ('stream', 'Stream'),64 ('xaxis', 'XAxis'),65 ('xbins', 'XBins'),66 ('yaxis', 'YAxis'),67 ('ybins', 'YBins'),68 ('zaxis', 'ZAxis')69 ]70 for object_name, expected_class_name in test_tuples:71 class_name = gr.object_name_to_class_name(object_name)72 msg = (object_name, expected_class_name, class_name)73 self.assertEqual(class_name, expected_class_name, msg=msg)74 def test_old_traces(self):75 # While the old trace classes exist, the newer should be returned.76 test_tuples = [77 ('histogram2dcontour', 'Histogram2dcontour')78 ]79 for object_name, expected_class_name in test_tuples:80 class_name = gr.object_name_to_class_name(object_name)81 msg = (object_name, expected_class_name, class_name)82 self.assertEqual(class_name, expected_class_name, msg=msg)83 def test_new_traces(self):84 # New traces should get have classes defined.85 test_tuples = [86 ('choropleth', 'Choropleth'),87 ('pie', 'Pie')88 ]89 for object_name, expected_class_name in test_tuples:90 class_name = gr.object_name_to_class_name(object_name)91 msg = (object_name, expected_class_name, class_name)92 self.assertEqual(class_name, expected_class_name, msg=msg)93 def test_new_non_trace_objects(self):94 # New objects get 'dict' or 'list'.95 test_tuples = [96 ('geo', 'dict'),97 ('shapes', 'list'),98 ('shape', 'dict'),99 ]100 for object_name, expected_class_name in test_tuples:101 class_name = gr.object_name_to_class_name(object_name)102 msg = (object_name, expected_class_name, class_name)103 self.assertEqual(class_name, expected_class_name, msg=msg)104class TestGetAttributesMethods(TestCase):105 def test_get_subplot_attributes(self):106 # importantly, layout should have a bunch of these107 layout_subplot_attributes = gr.get_subplot_attributes('layout')108 # there may be more...109 expected_attributes = ['xaxis', 'yaxis', 'geo', 'scene']110 for expected_attribute in expected_attributes:111 self.assertIn(expected_attribute, layout_subplot_attributes)112 def test_get_deprecated_attributes(self):113 # this may eventually break, but it's important to check *something*114 bar_deprecated_attributes = gr.get_deprecated_attributes('bar')115 expected_attributes = ['bardir']116 for expected_attribute in expected_attributes:117 self.assertIn(expected_attribute, bar_deprecated_attributes)118class TestGetAttributePathToObjectNames(TestCase):119 def test_layout_attributes(self):120 # layout attrs defined under traces should still show up under layout121 graph_reference_path = ('traces', 'box', 'layoutAttributes')122 expected_object_names = ('figure', 'layout')123 object_names = gr.attribute_path_to_object_names(graph_reference_path)124 self.assertEqual(object_names, expected_object_names)125 def test_trace_attributes(self):126 # trace attributes should be found under 'data' somewhere127 graph_reference_path = ('traces', 'scatter', 'attributes', 'marker',128 'line')129 expected_object_names = ('figure', 'data', 'scatter', 'marker', 'line')130 object_names = gr.attribute_path_to_object_names(graph_reference_path)131 self.assertEqual(object_names, expected_object_names)132class TestGetRole(TestCase):133 def test_get_role_no_value(self):134 # this is a bit fragile, but we pick a few stable values135 # (<object_name>, <attribute_name>, <parent_object_names>, <role>)136 test_tuples = [137 ('scatter', 'x', ('figure', 'data'), 'data'),138 ('scatter', 'marker', ('figure', 'data'), 'object'),139 ('marker', 'color', ('figure', 'data', 'scatter'), 'style'),140 ('layout', 'title', ('figure', ), 'info'),141 ('figure', 'data', (), 'object')142 ]143 for tup in test_tuples:144 object_name, key, parent_object_names, role = tup145 found_role = get_role(object_name, key,146 parent_object_names=parent_object_names)147 self.assertEqual(found_role, role, msg=tup)148 def test_get_role_with_value(self):149 # some attributes are conditionally considered data if they're arrays150 # (<object_name>, <attribute_name>, <parent_object_names>, <role>)151 test_tuples = [152 ('scatter', 'x', 'wh0cares', ('figure', 'data'), 'data'),153 ('scatter', 'marker', 'wh0cares', ('figure', 'data'), 'object'),154 ('marker', 'color', 'r', ('figure', 'data', 'scatter'), 'style'),155 ('marker', 'color', ['r'], ('figure', 'data', 'scatter'), 'data'),156 ]157 for tup in test_tuples:158 object_name, key, value, parent_object_names, role = tup159 found_role = get_role(object_name, key, value=value,160 parent_object_names=parent_object_names)...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

1# Copyright 2020 The KNIX Authors2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14import datetime15import json16import random17import sys18import time19import unittest20sys.path.append("../")21from mfn_test_utils import MFNTest22class JavaWorkflowManipulationTest(unittest.TestCase):23 #@unittest.skip("")24 def test_workflow_manipulation_java(self):25 test = MFNTest(workflow_filename="wf_workflow_manipulation_java.json")26 test_tuples = []27 test_tuples.append(('"float addWorkflowNext"', '"final_42.0_addWorkflowNext"'))28 test_tuples.append(('"float addDynamicNext"', '"final_42.0_addDynamicNext"'))29 test_tuples.append(('"float sendToFunctionNow"', '"final_42.0_sendToFunctionNow"'))30 test_tuples.append(('"float addDynamicWorkflowTrigger"', '"final_42.0_addDynamicWorkflowTrigger"'))31 test_tuples.append(('"float addDynamicWorkflowTriggerList"', '"final_42.0_addDynamicWorkflowTriggerList"'))32 test_tuples.append(('"int addWorkflowNext"', '"final_42_addWorkflowNext"'))33 test_tuples.append(('"int addDynamicNext"', '"final_42_addDynamicNext"'))34 test_tuples.append(('"int sendToFunctionNow"', '"final_42_sendToFunctionNow"'))35 test_tuples.append(('"int addDynamicWorkflowTrigger"', '"final_42_addDynamicWorkflowTrigger"'))36 test_tuples.append(('"int addDynamicWorkflowTriggerList"', '"final_42_addDynamicWorkflowTriggerList"'))37 test_tuples.append(('"double addWorkflowNext"', '"final_42.0_addWorkflowNext"'))38 test_tuples.append(('"double addDynamicNext"', '"final_42.0_addDynamicNext"'))39 test_tuples.append(('"double sendToFunctionNow"', '"final_42.0_sendToFunctionNow"'))40 test_tuples.append(('"double addDynamicWorkflowTrigger"', '"final_42.0_addDynamicWorkflowTrigger"'))41 test_tuples.append(('"double addDynamicWorkflowTriggerList"', '"final_42.0_addDynamicWorkflowTriggerList"'))42 test_tuples.append(('"list addWorkflowNext"', '"final_[myelement]_addWorkflowNext"'))43 test_tuples.append(('"list addDynamicNext"', '"final_[myelement]_addDynamicNext"'))44 test_tuples.append(('"list sendToFunctionNow"', '"final_[myelement]_sendToFunctionNow"'))45 test_tuples.append(('"list addDynamicWorkflowTrigger"', '"final_[myelement]_addDynamicWorkflowTrigger"'))46 test_tuples.append(('"list addDynamicWorkflowTriggerList"', '"final_[myelement]_addDynamicWorkflowTriggerList"'))47 test_tuples.append(('"string addWorkflowNext"', '"final_mystring_addWorkflowNext"'))48 test_tuples.append(('"string addDynamicNext"', '"final_mystring_addDynamicNext"'))49 test_tuples.append(('"string sendToFunctionNow"', '"final_mystring_sendToFunctionNow"'))50 test_tuples.append(('"string addDynamicWorkflowTrigger"', '"final_mystring_addDynamicWorkflowTrigger"'))51 test_tuples.append(('"string addDynamicWorkflowTriggerList"', '"final_mystring_addDynamicWorkflowTriggerList"'))52 test_tuples.append(('"dict addWorkflowNext"', '"final_{mykey=true}_addWorkflowNext"'))53 test_tuples.append(('"dict addDynamicNext"', '"final_{mykey=true}_addDynamicNext"'))54 test_tuples.append(('"dict sendToFunctionNow"', '"final_{mykey=true}_sendToFunctionNow"'))55 test_tuples.append(('"dict addDynamicWorkflowTrigger"', '"final_{mykey=true}_addDynamicWorkflowTrigger"'))56 test_tuples.append(('"dict addDynamicWorkflowTriggerList"', '"final_{mykey=true}_addDynamicWorkflowTriggerList"'))57 test_tuples.append(('"something_else addWorkflowNext"', '"final_null_addWorkflowNext"'))58 test_tuples.append(('"something_else addDynamicNext"', '"final_null_addDynamicNext"'))59 test_tuples.append(('"something_else sendToFunctionNow"', '"final_null_sendToFunctionNow"'))60 test_tuples.append(('"something_else addDynamicWorkflowTrigger"', '"final_null_addDynamicWorkflowTrigger"'))61 test_tuples.append(('"something_else addDynamicWorkflowTriggerList"', '"final_null_addDynamicWorkflowTriggerList"'))62 test.exec_tests(test_tuples)63def main():64 unittest.main()65if __name__ == '__main__':...

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