def plot_activity_test_generator(): for entry in plot_activity_test_data: string_start, string_end, exp_left, exp_width = entry yield "left", parse_date(string_start), parse_date( string_end), exp_left yield "width", parse_date(string_start), parse_date( string_end), exp_width
def test_first_day_of_month(self, string_date, from_string_date): date = parse_date(string_date) exp_result = parse_date(from_string_date) result = ut.first_day_of_month(date) self.assertEqual(exp_result, result)
def points(string_date): date = parse_date(string_date) return date_to_points(date, left=tpc['left'], right=tpc['right'], start_date=tpc['min_start_date'], end_date=tpc['max_end_date'])
def test_date_to_x_coordinate(self, string_test_date, expected_x): test_date = parse_date(string_test_date) x = self.plot_driver.date_to_x_coordinate(test_date) self.assertEqual(expected_x, x)
def plot_milestone_test_generator(): for entry in plot_milestone_test_data: string_start, milestone_width, exp_left = entry yield parse_date(string_start), milestone_width, exp_left
from unittest import TestCase from ddt import ddt, data, unpack from pptx.util import Cm from source.plot_driver import PlotDriver from source.tests.testing_utilities import parse_date, date_to_points tpc = { # Test Plot Config 'top': Cm(0), 'left': Cm(0), 'bottom': Cm(10), 'right': Cm(20), 'track_height': Cm(1), 'track_gap': Cm(0.5), 'min_start_date': parse_date('2021-01-01'), 'max_end_date': parse_date('2021-01-31'), 'activity_text_width': Cm(5), 'milestone_text_width': Cm(5), 'text_margin': Cm(0.1), 'activity_width': Cm(5), 'milestone_width': Cm(5), 'activity_shape': 'RECTANGLE', 'milestone_shape': 'DIAMOND' } def points(string_date): date = parse_date(string_date) return date_to_points(date, left=tpc['left'], right=tpc['right'],
def test_horizontal_layout(self, visual_parameters, activity_parameters, expected_case, expected_value): layout_attributes = ActivityLayoutAttributes('Swimlane-01', 1, 1, "shape") display_shape = VisualElementShape.RECTANGLE # parameters = test_case_01['parameters'] # expected_results = test_case_01['expected_results'] plan_visual_config = PlotDriver({ 'top': Cm(3.86), 'left': visual_parameters['visual_left'], 'bottom': Cm(20), 'right': Cm(33.87), 'track_height': Cm(0.6), 'track_gap': Cm(0.2), 'activity_text_width': Cm(5), 'milestone_text_width': Cm(5), 'text_margin': Cm(0.1), 'milestone_width': Cm(0.4), 'activity_shape': 'rectangle', 'milestone_shape': 'diamond', 'min_start_date': parse_date('2021-01-01'), 'max_end_date': parse_date('2021-07-31') }) plan_visual_config.num_days_in_date_range = activity_parameters[ 'num_days_in_date_range'] text_formatting = TextFormatting() formatting_1 = ShapeFormatting( Color(rgb=(1, 1, 1)), Color(rgb=(1, 1, 1)), None, text_formatting, ) activity = PlanActivity(12345, 'Dummy', 'bar', activity_parameters['activity_start_date'], activity_parameters['activity_end_date'], layout_attributes, display_shape, plan_visual_config, formatting_1, formatting_1, activity_parameters['today'], 1) pres = Presentation() slide_layout = pres.slide_layouts[0] slide = pres.slides.add_slide(slide_layout) shapes = slide.shapes shapes = activity.plot_ppt_shapes(shapes) if expected_case == 'num_shapes': self.assertEqual(expected_value, len(shapes)) elif expected_case == 'left_1': self.assertEqual(expected_value, shapes[0].left) elif expected_case == 'width_1': self.assertEqual(expected_value, shapes[0].width) elif expected_case == 'left_2': self.assertEqual(expected_value, shapes[1].left) elif expected_case == 'width_2': self.assertEqual(expected_value, shapes[1].width)
from unittest import TestCase from colour import Color from ddt import ddt, unpack, data from pptx import Presentation from pptx.util import Cm from source.plot_driver import PlotDriver from source.activity_layout_attributes import ActivityLayoutAttributes from source.plan_activity import PlanActivity from source.shape_formatting import ShapeFormatting from source.text_formatting import TextFormatting from source.visual_element_shape import VisualElementShape from source.tests.testing_utilities import parse_date visual_parameters_01 = { 'visual_start_date': parse_date('2021-01-01'), 'visual_end_date': parse_date('2021-07-31'), 'visual_left': Cm(0), 'visual_right': Cm(33.87), } test_cases = [ { 'parameters': { 'activity_start_date': parse_date('2021-08-11'), 'activity_end_date': parse_date('2021-12-14'), 'today': parse_date('2021-07-01'), 'num_days_in_date_range': 212 }, 'expected_results': { # Calculations are from Excel 'num_shapes': 1, 'left': 12768351,