예제 #1
0
def test_jqpc_simple_bar_horizontal_chart_ok2():
   """ Tests: test_jqpc_simple_bar_horizontal_chart_ok2
   """
   print('::: TEST: test_jqpc_simple_bar_horizontal_chart_ok2()')

   scripts_bar_chart_path = path_join(SCRIPT_PATH, 'scripts_bar_chart_test_jqpc_simple_bar_horizontal_chart_ok2')

   if path_exists(scripts_bar_chart_path):
      shutil_rmtree(scripts_bar_chart_path)

   js_css_resources_header, jqplotchart_script, html_chart_insert_tag = jqpc_simple_bar_chart(
      absolute_source_dir_path=scripts_bar_chart_path,
      script_src_tag_dir_path=path_relpath(scripts_bar_chart_path),
      chart_id='example_id',
      class_str='whatever',
      chart_title='JqPyCharts simple_bar_chart',
      chart_x_label='',
      chart_x_label_fontdict=None,
      chart_ticks_fontdict=None,
      chart_data_matrix=[
         ('Fat', 200, '#EAA228', ''),
         ('Protein', 21, '#4bb2c5', ''),
         ('Carbohydrate', 10, '#c5b47f', '')
      ],
      highlighter_prefix='Gram',
      background='#fffdf6',
      horizontal=True,
      draw_grid_lines=False,
      width_px=550,
      height_px=300,
      margin_top_px=0,
      margin_bottom_px=0,
      margin_right_px=0,
      margin_left_px=0)

   for resource_name in [
      'jquery.min.js',
      'jquery.jqplot.min.js',
      'jqplot.canvasAxisLabelRenderer.min.js',
      'jqplot.categoryAxisRenderer.min.js',
      'jqplot.canvasTextRenderer.min.js',
      'jqplot.barRenderer.min.js',
      'jqplot.pointLabels.min.js',
      'jquery.jqplot.min.css']:

      resource_dir_path__abspath = path_join(scripts_bar_chart_path, resource_name)
      resource_dir_path__relpath = path_relpath(resource_dir_path__abspath)
      if resource_dir_path__abspath[-2:] == 'js':
         check_line = '<script type="text/javascript" src="{}"></script>'.format(resource_dir_path__relpath)
         ok_(check_line in js_css_resources_header, msg=None)
      elif resource_dir_path__abspath[-3:] == 'css':
         check_line = '<link rel="stylesheet" type="text/css" href="{}">'.format(resource_dir_path__relpath)
         ok_(check_line in js_css_resources_header, msg=None)
      else:
         raise Err('test_jqpc_simple_bar_horizontal_chart_ok2', [
            '`resource_name`: <{}> must end with <.js> or <.css>'.format(resource_name)
         ])

   if path_exists(scripts_bar_chart_path):
      shutil_rmtree(scripts_bar_chart_path)
def test_jqpc_simple_pie_chart__expect_failure1():
    """ Tests: test_jqpc_simple_pie_chart__expect_failure1: chart_id with spaces
   """
    print('::: TEST: test_jqpc_simple_pie_chart__expect_failure1()')

    scripts_pie_chart_path = path_join(
        SCRIPT_PATH,
        'scripts_pie_chart_test_jqpc_simple_pie_chart__expect_failure1')

    if path_exists(scripts_pie_chart_path):
        shutil_rmtree(scripts_pie_chart_path)

    js_css_resources_header, jqplotchart_script, html_chart_insert_tag = jqpc_simple_pie_chart(
        absolute_source_dir_path=scripts_pie_chart_path,
        script_src_tag_dir_path=path_relpath(scripts_pie_chart_path),
        chart_id='example_id wrong can not have spaces',
        class_str='',
        chart_title='JqPyCharts simple_pie_chart',
        chart_data_matrix=[('Fat', 200, '#EAA228', 'Fat: 200 g'),
                           ('Protein', 21, '#4bb2c5', None),
                           ('Carbohydrate', 10, '#c5b47f',
                            'Carbohydrate: 10 g')],
        highlighter_prefix='',
        background='#fffdf6',
        legend_font_px=15,
        data_label_threshold=9.0,
        width_px=480,
        height_px=300,
        margin_top_px=0,
        margin_bottom_px=0,
        margin_right_px=0,
        margin_left_px=0)

    for resource_name in [
            'jquery.min.js', 'jquery.jqplot.min.js',
            'jqplot.highlighter.min.js', 'jqplot.canvasTextRenderer.min.js',
            'jqplot.pieRenderer.min.js', 'jquery.jqplot.min.css'
    ]:

        resource_dir_path__abspath = path_join(scripts_pie_chart_path,
                                               resource_name)
        resource_dir_path__relpath = path_relpath(resource_dir_path__abspath)
        if resource_dir_path__abspath[-2:] == 'js':
            check_line = '<script type="text/javascript" src="{}"></script>'.format(
                resource_dir_path__relpath)
            ok_(check_line in js_css_resources_header, msg=None)
        elif resource_dir_path__abspath[-3:] == 'css':
            check_line = '<link rel="stylesheet" type="text/css" href="{}">'.format(
                resource_dir_path__relpath)
            ok_(check_line in js_css_resources_header, msg=None)
        else:
            raise Err('test_jqpc_simple_pie_chart__expect_failure1', [
                '`resource_name`: <{}> must end with <.js> or <.css>'.format(
                    resource_name)
            ])

    if path_exists(scripts_pie_chart_path):
        shutil_rmtree(scripts_pie_chart_path)