Best Python code snippet using SeleniumBase
tests.py
Source:tests.py
...217 self.assertEqual(json.dumps(default), chart.get_options_json())218 self.assertEqual(self.series_objects, chart.get_series_objects())219 self.assertEqual(json.dumps(self.series_objects),220 chart.get_series_objects_json())221 def test_line_chart(self):222 chart = flot.LineChart(data_source=self.data_source,223 options=self.options)224 empty_options_chart = flot.LineChart(data_source=self.data_source,225 options={})226 json_data = chart.get_serieses()227 self.assertEqual([self.series_1, self.series_2], json_data)228 default = get_default_options("lines")229 self.assertEqual(default,230 empty_options_chart.get_options())231 default.update(self.options)232 self.assertEqual(default,233 chart.get_options())234 def test_bar_chart(self):235 chart = flot.BarChart(data_source=self.data_source,236 options=self.options)237 empty_options_chart = flot.BarChart(data_source=self.data_source,238 options={})239 json_data = chart.get_serieses()240 self.assertEqual([self.series_1, self.series_2], json_data)241 default = get_default_options("bars")242 self.assertEqual(default,243 empty_options_chart.get_options())244 default.update(self.options)245 self.assertEqual(default,246 chart.get_options())247 def test_point_chart(self):248 chart = flot.PointChart(data_source=self.data_source,249 options=self.options)250 empty_options_chart = flot.PointChart(data_source=self.data_source,251 options={})252 json_data = chart.get_serieses()253 self.assertEqual([self.series_1, self.series_2], json_data)254 default = get_default_options("points")255 self.assertEqual(default,256 empty_options_chart.get_options())257 default.update(self.options)258 self.assertEqual(default,259 chart.get_options())260class TestGchartRenderer(TestCase):261 def setUp(self):262 data = [263 ['Year', 'Sales', 'Expenses'],264 [2004, 1000, 400],265 [2005, 1170, 460],266 [2006, 660, 1120],267 [2007, 1030, 540]268 ]269 self.data_source = SimpleDataSource(data)270 self.data = data271 def test_line_chart(self):272 chart = gchart.LineChart(data_source=self.data_source)273 self.assertNotEqual(chart.as_html(), "")274 self.assertTrue("LineChart" in chart.as_html())275 def test_column_chart(self):276 chart = gchart.ColumnChart(data_source=self.data_source)277 self.assertNotEqual(chart.as_html(), "")278 self.assertTrue("Column" in chart.as_html())279 def test_bar_chart(self):280 chart = gchart.BarChart(data_source=self.data_source)281 self.assertNotEqual(chart.as_html(), "")282 self.assertTrue("BarChart" in chart.as_html())283 def test_candlestick_chart(self):284 chart = gchart.CandlestickChart(data_source=self.data_source)285 self.assertNotEqual(chart.as_html(), "")286 self.assertTrue("CandlestickChart" in chart.as_html())287 def test_gauge_chart(self):288 chart = gchart.GaugeChart(data_source=self.data_source)289 self.assertNotEqual(chart.as_html(), "")290 self.assertTrue("Gauge" in chart.as_html())291class TestYUIRenderer(TestCase):292 def setUp(self):293 data = [294 ['Year', 'Sales', 'Expenses'],295 [2004, 1000, 400],296 [2005, 1170, 460],297 [2006, 660, 1120],298 [2007, 1030, 540]299 ]300 self.data_source = SimpleDataSource(data)301 self.data = data302 def test_line_chart(self):303 chart = yui.LineChart(data_source=self.data_source)304 self.assertNotEqual(chart.as_html(), "")305 self.assertTrue("line" in chart.as_html())306class TestMatplotlibRenderer(TestCase):307 def setUp(self):308 data = [['Year', 'Sales', 'Expenses', 'Items Sold', 'Net Profit'],309 ['2004', 1000, 400, 100, 600],310 ['2005', 1170, 460, 120, 310],311 ['2006', 660, 1120, 50, -460],312 ['2007', 1030, 540, 100, 200]]313 self.data_source = SimpleDataSource(data)314 self.data = data315 def test_line_chart(self):316 chart = matplotlib_renderer.LineChart(self.data_source)317 self.assertNotEqual(chart.as_html(), "")318 def test_bar_chart(self):319 chart = matplotlib_renderer.BarChart(self.data_source)...
test_datawrapper.py
Source:test_datawrapper.py
1"""Tests chart generation with Datawrapper.2Note that these tests are primarily "visual". Check test/rendered_charts folder3that the generated charts look as expected.4"""5from newsworthycharts import DatawrapperChart6from newsworthycharts.storage import LocalStorage7import os8from copy import deepcopy9from dotenv import load_dotenv10load_dotenv()11# store test charts to this folder for visual verfication12OUTPUT_DIR = "test/rendered_charts"13local_storage = LocalStorage(OUTPUT_DIR)14try:15 DATAWRAPPER_API_KEY = os.environ["DATAWRAPPER_API_KEY"]16except KeyError:17 raise Exception("A 'DATAWRAPPER_API_KEY' must be set to run these test. "18 "Get it here: https://app.datawrapper.de/account/api-tokens")19TEST_LINE_CHART = {20 "width": 800,21 "height": 0, # 0 for auto height22 "title": "Here is a title from chart obj",23 "data": [24 [25 ["2016-01-01", -2],26 ["2017-01-01", 5],27 ["2018-01-01", 2],28 ["2019-01-01", 2]29 ],30 [31 ["2016-01-01", -4],32 ["2017-01-01", 4],33 ["2018-01-01", 1],34 ["2019-01-01", -1]35 ]36 ],37 "labels": [38 u"LuleÃ¥",39 u"Happaranda",40 ],41 "caption": "Ministry of stats",42 "dw_data": {43 "type": "d3-lines",44 "metadata": {45 "describe": {46 "byline": "Newsworthy"47 }48 }49 },50}51def test_basic_chart():52 chart_obj = deepcopy(TEST_LINE_CHART)53 c = DatawrapperChart.init_from(chart_obj, storage=local_storage,54 language="sv-SE")55 c.render_all("dw_chart_basic")56def test_chart_with_highlight():57 chart_obj = deepcopy(TEST_LINE_CHART)58 chart_obj["highlight"] = "LuleÃ¥"59 c = DatawrapperChart.init_from(chart_obj, storage=local_storage,60 language="sv-SE")61 c.render_all("dw_chart_with_highlight")62def test_line_chart_with_pct():63 chart_obj = deepcopy(TEST_LINE_CHART)64 chart_obj["units"] = "percent"65 chart_obj["decimals"] = 166 chart_obj["data"] = [67 [68 ["2016-01-01", -.211],69 ["2017-01-01", .536],70 ["2018-01-01", .213],71 ["2019-01-01", .221]72 ],73 [74 ["2016-01-01", -.431],75 ["2017-01-01", None],76 ["2018-01-01", .118],77 ["2019-01-01", -.136]78 ]79 ]80 c = DatawrapperChart.init_from(chart_obj, storage=local_storage,81 language="sv-SE")82 c.render_all("dw_line_chart_with_pct")83def test_vertical_bar_chart_with_highlight():84 chart_obj = deepcopy(TEST_LINE_CHART)85 chart_obj["data"] = [86 [87 ["2016-01-01", -2],88 ["2017-01-01", 5],89 ["2018-01-01", 2],90 ["2019-01-01", 2]91 ],92 ]93 chart_obj["labels"] = ["LuleÃ¥"]94 chart_obj["highlight"] = "2019-01-01"95 chart_obj["dw_data"]["type"] = "column-chart"96 c = DatawrapperChart.init_from(chart_obj, storage=local_storage,97 language="sv-SE")98 c.render_all("dw_vertical_bar_chart_with_highlight")99def test_horizontal_bar_chart_with_highlight():100 chart_obj = deepcopy(TEST_LINE_CHART)101 chart_obj["data"] = [102 [103 ["Solna", -.221],104 ["Stockholm", .523],105 ["Sundbyberg", .212],106 ],107 ]108 chart_obj["units"] = "percent"109 chart_obj["labels"] = ["Förändring (%)"]110 chart_obj["highlight"] = "Stockholm"111 chart_obj["dw_data"]["type"] = "d3-bars"112 c = DatawrapperChart.init_from(chart_obj, storage=local_storage,113 language="sv-SE")114 c.render_all("dw_horizontal_bar_chart_with_highlight")115def test_table():116 chart_obj = {117 "width": 600,118 "height": 0,119 "title": "NÃ¥gra svenska städer jag gillar",120 "labels": ["Kommun", "Värde", "Kategori"],121 "data": [122 {123 "region": "Göteborg",124 "value": 1.1,125 "category": "Västkust",126 },127 {128 "region": "Stockholm",129 "value": 2.1,130 "category": "Ãstkust",131 },132 ],133 "dw_data": {134 "type": "tables",135 }136 }137 c = DatawrapperChart.init_from(chart_obj, storage=local_storage,138 language="sv-SE")139 c.render_all("dw_table")140def test_choropleth_map():141 chart_obj = {142 "width": 400,143 "height": 500,144 "title": "Här är en karta",145 "data": [146 {147 "region": "Västra Götalands län",148 "value": 1.1,149 },150 {151 "region": "Stockholms län",152 "value": 2.1,153 },154 {155 "region": "SkÃ¥ne län",156 "value": 3.1,157 },158 {159 "region": "Ãrebro län",160 "value": 6.2,161 }162 ],163 "dw_data": {164 "type": "d3-maps-choropleth",165 "metadata": {166 "axes": {167 "keys": "region",168 "values": "value"169 },170 "visualize": {171 "basemap": "sweden-counties"172 }173 }174 }175 }176 c = DatawrapperChart.init_from(chart_obj, storage=local_storage,177 language="sv-SE")178 c.render_all("dw_map_choropleth")179def test_pie_chart():180 metadata = {181 'data': {182 'transpose': False,183 'vertical-header': True,184 'horizontal-header': True185 },186 'publish': {187 'embed-width': 600,188 'chart-height': 330,189 'embed-height': 415190 },191 'annotate': {'notes': ''},192 'describe': {193 'intro': '',194 'byline': '',195 'source-url': '',196 'source-name': '',197 'number-append': '',198 'number-format': '-',199 'number-divisor': 0,200 'number-prepend': '',201 },202 'visualize': {203 'group': {'text': 'Other', 'num_slices': 5},204 'x-grid': 'off',205 'y-grid': 'on',206 'scale-y': 'linear',207 'labeling': 'right',208 'pie_size': {'inside_labels': 75, 'outside_labels': 50},209 'color_key': {210 'stack': False,211 'enabled': False,212 'position': 'top',213 'label_values': False,214 },215 'base-color': 0,216 'base_color': 0,217 'fill-below': False,218 'line-dashes': [],219 'line-widths': [],220 'slice_order': 'descending',221 'fill-between': False,222 'label-colors': False,223 'label-margin': 0,224 'line-symbols': False,225 'show_percent': False,226 'custom-colors': {227 'Möjligen bokningsbara': 6,228 'Bekfräftat tillgängliga': 5,229 },230 'inside_labels': {'enabled': False},231 'interpolation': 'linear',232 'show-tooltips': True,233 'x-tick-format': 'YYYY',234 'y-grid-format': '0,0.[00]',235 'y-grid-labels': 'auto',236 'chart-type-set': True,237 'custom-range-x': ['', ''],238 'custom-range-y': ['', ''],239 'custom-ticks-x': '',240 'custom-ticks-y': '',241 'outside_labels': {'edge': False, 'color': False, 'enabled': True},242 'rotation_angle': 0,243 'connector-lines': True,244 'donut_hole_size': 50,245 'line-symbols-on': 'both',246 'small_multiples': {247 'group_value_label': {248 'type': 'total',249 'enabled': False,250 'total_text': 'Total',251 'single_selected_row': 0,252 },253 'min_col_grid_width': 120,254 },255 'y-grid-subdivide': True,256 'custom-area-fills': [],257 'label_text_slices': True,258 'line-symbols-size': 3.5,259 'line-value-labels': False,260 'donut_center_label': {261 'type': 'total',262 'enabled': False,263 'total_text': 'Total',264 'custom_text': '',265 'single_selected_row': 0,266 },267 'highlighted-series': [],268 'highlighted-values': [],269 'line-symbols-shape': 'circle',270 'value-label-format': '0,0.[00]',271 'y-grid-label-align': 'left',272 'label_values_slices': True,273 'line-symbols-opacity': 1,274 'area-fill-color-below': '#cccccc',275 'tooltip-number-format': '0,0.[00]',276 'area-fill-color-between': '#cccccc',277 'line-symbols-shape-multiple': []278 },279 'json_error': None,280 }281 chart_obj = {282 "data": [283 {284 "key": 'Möjligen bokningsbara',285 "value": 35,286 },287 {288 "key": 'Bekfräftat tillgängliga',289 "value": 65290 }291 ],292 "width": 400,293 "height": 300,294 "dw_data": {295 "type": 'd3-donuts',296 "metadata": metadata,297 }298 }299 c = DatawrapperChart.init_from(chart_obj, storage=local_storage,300 language="sv-SE")301 c.render("dw_pie1", "png")302def test_pie_chart2():303 chart_obj = {304 'width': 380, 'height': 250,305 'format': 'png',306 'theme': 'newsworthy',307 'lang': 'sv',308 'overwrite': False,309 'chart_engine': 'DatawrapperChart',310 'data': [311 {312 'key': 'Möjligen boknings- bara',313 'value': 0.7186602152835304314 }, {315 'key': 'Tillgängliga', 'value': 0.2813397847164696316 }317 ],318 'datatype': None,319 'decimals': 0,320 'dw_data': {321 'metadata': {322 'visualize': {323 'custom-colors': {324 'Möjligen boknings- bara': '#cdcdcd',325 'Tillgängliga': '#5aa69d',326 },327 'donut_hole_size': 50,328 'inside_labels': {'enabled': False},329 'line-symbols-size': 6.5,330 'outside_labels': {331 'color': False,332 'edge': False,333 'enabled': True,334 },335 'pie_size': {336 'inside_labels': 75,337 'outside_labels': 50,338 },339 'slice_order': 'original',340 'value-label-format': '0%',341 }342 },343 'type': 'd3-donuts'344 },345 'labels': [],346 'measures': [],347 'periodicity':348 'yearly',349 'series': [],350 'source': None,351 'type': 'bars',352 'units': 'percent',353 'title': None,354 'key': '2837248355',355 'language': 'sv',356 'style': 'newsworthy',357 'primary_color': '#5aa69d',358 'size': 'normal',359 'bar_orientation':360 'horizontal',361 'show_category_ticks': True,362 'ymin': 0,363 'ticks': 'yearly',364 'highlight_change': False365 }366 c = DatawrapperChart.init_from(chart_obj, storage=local_storage,367 language="sv-SE")...
test_urls.py
Source:test_urls.py
1from django.test import TestCase as DJTest2from django.urls import reverse3class TestUrls(DJTest):4 def test_line_chart(self):5 print(reverse("prisjakt:test_line_chart"))6 self.assertEqual(reverse("prisjakt:test_line_chart"), "/prisjakt/line_chart")7 def test_scatter_plot(self):8 print(reverse("prisjakt:test_scatter_plot"))9 self.assertEqual(10 reverse("prisjakt:test_scatter_plot"), "/prisjakt/scatter_plot"...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!