How to use load_plugins method in yandex-tank

Best Python code snippet using yandex-tank

test_zero.py

Source:test_zero.py Github

copy

Full Screen

...17 }18 def tearDown(self):19 ZeroPlugin.listeners = None20 self.teardown_beets()21 self.unload_plugins()22 def test_no_patterns(self):23 self.config['zero']['fields'] = ['comments', 'month']24 item = self.add_item_fixture(25 comments=u'test comment',26 title=u'Title',27 month=1,28 year=2000,29 )30 item.write()31 self.load_plugins('zero')32 item.write()33 mf = MediaFile(syspath(item.path))34 self.assertIsNone(mf.comments)35 self.assertIsNone(mf.month)36 self.assertEqual(mf.title, u'Title')37 self.assertEqual(mf.year, 2000)38 def test_pattern_match(self):39 self.config['zero']['fields'] = ['comments']40 self.config['zero']['comments'] = [u'encoded by']41 item = self.add_item_fixture(comments=u'encoded by encoder')42 item.write()43 self.load_plugins('zero')44 item.write()45 mf = MediaFile(syspath(item.path))46 self.assertIsNone(mf.comments)47 def test_pattern_nomatch(self):48 self.config['zero']['fields'] = ['comments']49 self.config['zero']['comments'] = [u'encoded by']50 item = self.add_item_fixture(comments=u'recorded at place')51 item.write()52 self.load_plugins('zero')53 item.write()54 mf = MediaFile(syspath(item.path))55 self.assertEqual(mf.comments, u'recorded at place')56 def test_do_not_change_database(self):57 self.config['zero']['fields'] = ['year']58 item = self.add_item_fixture(year=2000)59 item.write()60 self.load_plugins('zero')61 item.write()62 self.assertEqual(item['year'], 2000)63 def test_change_database(self):64 self.config['zero']['fields'] = ['year']65 self.config['zero']['update_database'] = True66 item = self.add_item_fixture(year=2000)67 item.write()68 self.load_plugins('zero')69 item.write()70 self.assertEqual(item['year'], 0)71 def test_album_art(self):72 self.config['zero']['fields'] = ['images']73 path = self.create_mediafile_fixture(images=['jpg'])74 item = Item.from_path(path)75 self.load_plugins('zero')76 item.write()77 mf = MediaFile(syspath(path))78 self.assertEqual(0, len(mf.images))79 def test_auto_false(self):80 self.config['zero']['fields'] = ['year']81 self.config['zero']['update_database'] = True82 self.config['zero']['auto'] = False83 item = self.add_item_fixture(year=2000)84 item.write()85 self.load_plugins('zero')86 item.write()87 self.assertEqual(item['year'], 2000)88 def test_subcommand_update_database_true(self):89 item = self.add_item_fixture(90 year=2016,91 day=13,92 month=3,93 comments=u'test comment'94 )95 item.write()96 item_id = item.id97 self.config['zero']['fields'] = ['comments']98 self.config['zero']['update_database'] = True99 self.config['zero']['auto'] = False100 self.load_plugins('zero')101 with control_stdin('y'):102 self.run_command('zero')103 mf = MediaFile(syspath(item.path))104 item = self.lib.get_item(item_id)105 self.assertEqual(item['year'], 2016)106 self.assertEqual(mf.year, 2016)107 self.assertEqual(mf.comments, None)108 self.assertEqual(item['comments'], u'')109 def test_subcommand_update_database_false(self):110 item = self.add_item_fixture(111 year=2016,112 day=13,113 month=3,114 comments=u'test comment'115 )116 item.write()117 item_id = item.id118 self.config['zero']['fields'] = ['comments']119 self.config['zero']['update_database'] = False120 self.config['zero']['auto'] = False121 self.load_plugins('zero')122 with control_stdin('y'):123 self.run_command('zero')124 mf = MediaFile(syspath(item.path))125 item = self.lib.get_item(item_id)126 self.assertEqual(item['year'], 2016)127 self.assertEqual(mf.year, 2016)128 self.assertEqual(item['comments'], u'test comment')129 self.assertEqual(mf.comments, None)130 def test_subcommand_query_include(self):131 item = self.add_item_fixture(132 year=2016,133 day=13,134 month=3,135 comments=u'test comment'136 )137 item.write()138 self.config['zero']['fields'] = ['comments']139 self.config['zero']['update_database'] = False140 self.config['zero']['auto'] = False141 self.load_plugins('zero')142 self.run_command('zero', 'year: 2016')143 mf = MediaFile(syspath(item.path))144 self.assertEqual(mf.year, 2016)145 self.assertEqual(mf.comments, None)146 def test_subcommand_query_exclude(self):147 item = self.add_item_fixture(148 year=2016,149 day=13,150 month=3,151 comments=u'test comment'152 )153 item.write()154 self.config['zero']['fields'] = ['comments']155 self.config['zero']['update_database'] = False156 self.config['zero']['auto'] = False157 self.load_plugins('zero')158 self.run_command('zero', 'year: 0000')159 mf = MediaFile(syspath(item.path))160 self.assertEqual(mf.year, 2016)161 self.assertEqual(mf.comments, u'test comment')162 def test_no_fields(self):163 item = self.add_item_fixture(year=2016)164 item.write()165 mediafile = MediaFile(syspath(item.path))166 self.assertEqual(mediafile.year, 2016)167 item_id = item.id168 self.load_plugins('zero')169 with control_stdin('y'):170 self.run_command('zero')171 item = self.lib.get_item(item_id)172 self.assertEqual(item['year'], 2016)173 self.assertEqual(mediafile.year, 2016)174 def test_whitelist_and_blacklist(self):175 item = self.add_item_fixture(year=2016)176 item.write()177 mf = MediaFile(syspath(item.path))178 self.assertEqual(mf.year, 2016)179 item_id = item.id180 self.config['zero']['fields'] = [u'year']181 self.config['zero']['keep_fields'] = [u'comments']182 self.load_plugins('zero')183 with control_stdin('y'):184 self.run_command('zero')185 item = self.lib.get_item(item_id)186 self.assertEqual(item['year'], 2016)187 self.assertEqual(mf.year, 2016)188 def test_keep_fields(self):189 item = self.add_item_fixture(year=2016, comments=u'test comment')190 self.config['zero']['keep_fields'] = [u'year']191 self.config['zero']['fields'] = None192 self.config['zero']['update_database'] = True193 tags = {194 'comments': u'test comment',195 'year': 2016,196 }197 self.load_plugins('zero')198 z = ZeroPlugin()199 z.write_event(item, item.path, tags)200 self.assertEqual(tags['comments'], None)201 self.assertEqual(tags['year'], 2016)202 def test_keep_fields_removes_preserved_tags(self):203 self.config['zero']['keep_fields'] = [u'year']204 self.config['zero']['fields'] = None205 self.config['zero']['update_database'] = True206 z = ZeroPlugin()207 self.assertNotIn('id', z.fields_to_progs)208 def test_fields_removes_preserved_tags(self):209 self.config['zero']['fields'] = [u'year id']210 self.config['zero']['update_database'] = True211 z = ZeroPlugin()212 self.assertNotIn('id', z.fields_to_progs)213 def test_empty_query_n_response_no_changes(self):214 item = self.add_item_fixture(215 year=2016,216 day=13,217 month=3,218 comments=u'test comment'219 )220 item.write()221 item_id = item.id222 self.config['zero']['fields'] = ['comments']223 self.config['zero']['update_database'] = True224 self.config['zero']['auto'] = False225 self.load_plugins('zero')226 with control_stdin('n'):227 self.run_command('zero')228 mf = MediaFile(syspath(item.path))229 item = self.lib.get_item(item_id)230 self.assertEqual(item['year'], 2016)231 self.assertEqual(mf.year, 2016)232 self.assertEqual(mf.comments, u'test comment')233 self.assertEqual(item['comments'], u'test comment')234def suite():235 return unittest.TestLoader().loadTestsFromName(__name__)236if __name__ == '__main__':...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

1from django.shortcuts import render, redirect2from django.apps.registry import apps # dina dodala3# Create your views here.4from core_django_app.models import Graph5from core_django_app.apps import CoreDjangoAppConfig6def index(request):7 config = apps.get_app_config('core_django_app')8 title = config.verbose_name9 load_plugins = config.load_data_plugins10 visualize_plugins = config.visualize_data_plugins11 return render(request, "index.html", {"title": title,12 "load_plugins": load_plugins,13 "visualize_plugins": visualize_plugins})14def visualize_data(request):15 if request.method == 'POST':16 config = apps.get_app_config('core_django_app')17 load_plugins = config.load_data_plugins18 visualize_plugins = config.visualize_data_plugins19 if config.graph is None:20 return render(request, "index.html", {"title": config.verbose_name,21 "data_not_loaded": True,22 "load_plugins": load_plugins,23 "visualize_plugins": visualize_plugins})24 # TODO: Spojiti ova dva naredna ifa25 if request.POST.get('visualization_plugin') == 'SimpleVisualization':26 plugin = config.visualize_data_plugins['SimpleVisualization']27 config.chosen_visualize_plugin = plugin28 visualization = plugin.visualize(config.graph.get_json_graph())29 return render(request, "index.html", {"title": "Main View",30 "visualization": visualization,31 "data_visualized": True,32 "data_loaded": True,33 "graph": config.graph,34 "load_plugins": load_plugins,35 "visualize_plugins": visualize_plugins})36 if request.POST.get('visualization_plugin') == 'ComplexVisualization':37 plugin = config.visualize_data_plugins['ComplexVisualization']38 config.chosen_visualize_plugin = plugin39 visualization = plugin.visualize(config.graph.get_json_graph())40 return render(request, "index.html", {"title": "Main View",41 "visualization": visualization,42 "data_visualized": True,43 "data_loaded": True,44 "graph": config.graph,45 "load_plugins": load_plugins,46 "visualize_plugins": visualize_plugins})47 else:48 return redirect('index')49def load_data(request):50 if request.method == 'POST':51 config = apps.get_app_config('core_django_app')52 load_plugins = config.load_data_plugins53 visualize_plugins = config.visualize_data_plugins54 if request.POST.get('source_plugin') == 'XMLDataLoader':55 try:56 xml_file = request.FILES['xml_file'].read()57 except KeyError:58 return render(request, "index.html", {"title": config.verbose_name,59 "data_not_loaded": True,60 "load_plugins": load_plugins,61 "visualize_plugins": visualize_plugins})62 xml_file_utf8 = str(xml_file, 'UTF-8')63 plugin = config.load_data_plugins['XMLDataLoader']64 config.graph = plugin.load_data(xml_file_utf8)65 config.chosen_load_plugin = plugin66 return render(request, "index.html", {"title": "Data Loaded",67 "data_loaded": True,68 "graph": config.graph,69 "load_plugins": load_plugins,70 "visualize_plugins": visualize_plugins})71 if request.POST.get('source_plugin') == 'DeezerDataLoader':72 playlist_path = request.POST.get('playlist_link')73 if playlist_path is None or playlist_path == '':74 return render(request, "index.html", {"title": config.verbose_name,75 "data_not_loaded": True,76 "load_plugins": load_plugins,77 "visualize_plugins": visualize_plugins})78 plugin = config.load_data_plugins['DeezerDataLoader']79 config.graph = plugin.load_data(playlist_path)80 return render(request, "index.html", {"title": "Data Loaded",81 "data_loaded": True,82 "graph": config.graph,83 "load_plugins": load_plugins,84 "visualize_plugins": visualize_plugins})85 else:86 return redirect('index')87def search_data(request):88 config = apps.get_app_config('core_django_app')89 if config.chosen_visualize_plugin is None:90 return redirect("index")91 parameter = request.POST["search_input"]92 old_graph = config.graph93 new_graph = old_graph.create_search_graph(parameter)94 plugin = config.chosen_visualize_plugin95 visualization = plugin.visualize(new_graph.get_json_graph())96 return render(request, "index.html", {"title": "Main View",97 "visualization": visualization,98 "graph": new_graph,99 "data_visualized": True,100 "data_loaded": True,101 "load_plugins": config.load_data_plugins,102 "visualize_plugins": config.visualize_data_plugins})103def query_format_correct(query):104 tokens = query.split(" ")105 if len(tokens) < 3:106 return False107 if tokens[1] not in ["==", "!=", ">", "<", "<=", ">="]:108 return False109 return True110def get_query_tokens(query):111 parts = query.split(" ")112 return [parts[0], parts[1], " ".join(parts[2:])]113def filter_data(request):114 config = apps.get_app_config('core_django_app')115 plugin = config.chosen_visualize_plugin116 # Preventing filtering if no data is displayed117 if config.chosen_visualize_plugin is None:118 return redirect("index")119 query = request.POST["filter_input"]120 if not query_format_correct(query):121 # if the query format isn't correct, we show the original graph again with an error message122 visualization = plugin.visualize(config.graph.get_json_graph())123 return render(request, "index.html", {"title": "Main View",124 "visualization": visualization,125 "graph": config.graph,126 "data_visualized": True,127 "data_loaded": True,128 "error_message": "Incorrect filter query format!",129 "load_plugins": config.load_data_plugins,130 "visualize_plugins": config.visualize_data_plugins})131 old_graph = config.graph132 new_graph = old_graph.create_filter_graph(get_query_tokens(query))133 visualization = plugin.visualize(new_graph.get_json_graph())134 return render(request, "index.html", {"title": "Main View",135 "visualization": visualization,136 "graph": new_graph,137 "data_visualized": True,138 "data_loaded": True,139 "load_plugins": config.load_data_plugins,...

Full Screen

Full Screen

test_marshaller_collection_priority.py

Source:test_marshaller_collection_priority.py Github

copy

Full Screen

1# Copyright (c) 2014-2016, Freja Nordsiek2# All rights reserved.3#4# Redistribution and use in source and binary forms, with or without5# modification, are permitted provided that the following conditions are6# met:7#8# 1. Redistributions of source code must retain the above copyright9# notice, this list of conditions and the following disclaimer.10#11# 2. Redistributions in binary form must reproduce the above copyright12# notice, this list of conditions and the following disclaimer in the13# documentation and/or other materials provided with the distribution.14#15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT19# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26import random27from nose.tools import raises28from nose.tools import assert_equal as assert_equal_nose29import hdf5storage30import hdf5storage.Marshallers31random.seed()32# Check if the example package is installed because some tests will33# depend on it.34try:35 from example_hdf5storage_marshaller_plugin import SubListMarshaller36 has_example_hdf5storage_marshaller_plugin = True37except:38 has_example_hdf5storage_marshaller_plugin = False39# Need a new marshaller that does nothing.40class JunkMarshaller(hdf5storage.Marshallers.TypeMarshaller):41 pass42@raises(TypeError)43def check_error_non_tuplelist(obj):44 hdf5storage.MarshallerCollection(priority=obj)45def test_error_non_tuplelist():46 for v in (None, True, 1, 2.3, '39va', b'391', set(), dict()):47 yield check_error_non_tuplelist, v48@raises(ValueError)49def test_error_missing_element():50 need = ('builtin', 'user', 'plugin')51 hdf5storage.MarshallerCollection(priority=[random.choice(need)52 for i in range(2)])53@raises(ValueError)54def test_error_extra_element():55 hdf5storage.MarshallerCollection(priority=('builtin', 'user',56 'plugin', 'extra'))57def test_builtin_plugin_user():58 m = JunkMarshaller()59 mc = hdf5storage.MarshallerCollection(load_plugins=True,60 priority=('builtin', 'plugin',61 'user'),62 marshallers=(m, ))63 assert_equal_nose(m, mc._marshallers[-1])64 if has_example_hdf5storage_marshaller_plugin:65 assert isinstance(mc._marshallers[-2],66 SubListMarshaller)67def test_builtin_user_plugin():68 m = JunkMarshaller()69 mc = hdf5storage.MarshallerCollection(load_plugins=True,70 priority=('builtin', 'user',71 'plugin'),72 marshallers=(m, ))73 if has_example_hdf5storage_marshaller_plugin:74 assert isinstance(mc._marshallers[-1],75 SubListMarshaller)76 assert_equal_nose(m, mc._marshallers[-2])77 else:78 assert_equal_nose(m, mc._marshallers[-1])79def test_plugin_builtin_user():80 m = JunkMarshaller()81 mc = hdf5storage.MarshallerCollection(load_plugins=True,82 priority=('plugin', 'builtin',83 'user'),84 marshallers=(m, ))85 assert_equal_nose(m, mc._marshallers[-1])86 if has_example_hdf5storage_marshaller_plugin:87 assert isinstance(mc._marshallers[0],88 SubListMarshaller)89def test_plugin_user_builtin():90 m = JunkMarshaller()91 mc = hdf5storage.MarshallerCollection(load_plugins=True,92 priority=('plugin', 'user',93 'builtin'),94 marshallers=(m, ))95 if has_example_hdf5storage_marshaller_plugin:96 assert isinstance(mc._marshallers[0],97 SubListMarshaller)98 assert_equal_nose(m, mc._marshallers[1])99 else:100 assert_equal_nose(m, mc._marshallers[0])101def test_user_builtin_plugin():102 m = JunkMarshaller()103 mc = hdf5storage.MarshallerCollection(load_plugins=True,104 priority=('user', 'builtin',105 'plugin'),106 marshallers=(m, ))107 assert_equal_nose(m, mc._marshallers[0])108 if has_example_hdf5storage_marshaller_plugin:109 assert isinstance(mc._marshallers[-1],110 SubListMarshaller)111def test_user_plugin_builtin():112 m = JunkMarshaller()113 mc = hdf5storage.MarshallerCollection(load_plugins=True,114 priority=('user', 'plugin',115 'builtin'),116 marshallers=(m, ))117 assert_equal_nose(m, mc._marshallers[0])118 if has_example_hdf5storage_marshaller_plugin:119 assert isinstance(mc._marshallers[1],...

Full Screen

Full Screen

test_discover.py

Source:test_discover.py Github

copy

Full Screen

...40 def test_load_plugins_from_dir_successful(self, mock_os_walk,41 mock_find_module,42 mock_load_module, mock_isdir):43 test_path = "/somewhere"44 discover.load_plugins(test_path)45 expected = [46 mock.call("plugin1", ["/somewhere"]),47 mock.call("plugin2", ["/somewhere/subdir"]),48 mock.call("plugin3", ["/somewhere/subdir/subsubdir"])49 ]50 self.assertEqual(expected, mock_find_module.mock_calls)51 self.assertEqual(3, len(mock_load_module.mock_calls))52 @mock.patch("%s.os.path.isfile" % DISCOVER, return_value=True)53 @mock.patch("%s.imp.load_source" % DISCOVER)54 def test_load_plugins_from_file_successful(self, mock_load_source,55 mock_isfile):56 discover.load_plugins("/somewhere/plugin.py")57 expected = [mock.call("plugin", "/somewhere/plugin.py")]58 self.assertEqual(expected, mock_load_source.mock_calls)59 @mock.patch("%s.os" % DISCOVER)60 def test_load_plugins_from_nonexisting_and_empty_dir(self, mock_os):61 # test no fails for nonexisting directory62 mock_os.path.isdir.return_value = False63 discover.load_plugins("/somewhere")64 # test no fails for empty directory65 mock_os.path.isdir.return_value = True66 mock_os.walk.return_value = []67 discover.load_plugins("/somewhere")68 @mock.patch("%s.os.path.isfile" % DISCOVER, return_value=True)69 def test_load_plugins_from_file_fails(self, mock_isfile):70 discover.load_plugins("/somewhere/plugin.py")71 @mock.patch("%s.os.path.isfile" % DISCOVER, return_value=False)72 def test_load_plugins_from_nonexisting_file(self, mock_isfile):73 # test no fails for nonexisting file74 discover.load_plugins("/somewhere/plugin.py")75 @mock.patch("%s.imp.load_module" % DISCOVER, side_effect=Exception())76 @mock.patch("%s.imp.find_module" % DISCOVER)77 @mock.patch("%s.os.path" % DISCOVER, return_value=True)78 @mock.patch("%s.os.walk" % DISCOVER,79 return_value=[("/etc/.rally/plugins", [], ("load_it.py", ))])80 def test_load_plugins_fails(self, mock_os_walk, mock_os_path,81 mock_find_module, mock_load_module):82 # test no fails if module is broken83 # TODO(olkonami): check exception is handled correct...

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 yandex-tank 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