def test_responsive_size(): """A ResponsiveSize is a way to state what size something should be on each mentioned DeviceClass.""" responsive_size = ResponsiveSize(xs=1, sm=2, lg=None) specified_sizes = responsive_size.device_options assert DeviceClass('lg') not in specified_sizes assert specified_sizes == {DeviceClass('xs'): 1, DeviceClass('sm'): 2}
def test_device_class_identity(): """Each supported DeviceClass is identified by a string; you cannot create one that is not supported.""" device_class = DeviceClass('lg') assert device_class.name == 'lg' with expected(ProgrammerError, test='Invalid device class name: unsupported, should be one of xs,sm,md,lg,xl.*'): DeviceClass('unsupported')
def test_previous_device_class(): """You can find the supported DeviceClass smaller than a given one.""" device_class = DeviceClass('sm') assert device_class.one_smaller.name == 'xs' # Case: when there is no class smaller than given device_class = DeviceClass('xs') assert device_class.one_smaller == None
def previous_device_class(fixture): """You can find the supported DeviceClass smaller than a given one.""" device_class = DeviceClass('sm') vassert( device_class.one_smaller.class_label == 'xs' ) # Case: when there is no class smaller than given device_class = DeviceClass('xs') vassert( device_class.one_smaller == None )
def test_allowed_sizes(): """The device classes for which sizes can be specified.""" size = ResponsiveSize(xs=1, sm=2, md=3, lg=4, xl=5) assert size.device_options == { DeviceClass('xs'): 1, DeviceClass('sm'): 2, DeviceClass('md'): 3, DeviceClass('lg'): 4, DeviceClass('xl'): 5 }
def device_class_identity(fixture): """Each supported DeviceClass is identified by a string; you cannot create one that is not supported.""" device_class = DeviceClass('lg') vassert( device_class.class_label == 'lg' ) def check_ex(ex): vassert( six.text_type(ex).startswith('"unsupported" should be one of: "xs","sm","md","lg","xl"') ) with expected(ProgrammerError, test=check_ex): DeviceClass('unsupported')
def test_previous_device_classes(): """You can find the ordered list of all supported DeviceClasses smaller than a given one.""" device_class = DeviceClass('md') previous_device_classes = [i.name for i in device_class.all_smaller] assert previous_device_classes == ['xs', 'sm'] # Case: when there is no class smaller than given device_class = DeviceClass('xs') previous_device_classes = device_class.all_smaller assert previous_device_classes == []
def previous_device_classes(fixture): """You can find the ordered list of all supported DeviceClasses smaller than a given one.""" device_class = DeviceClass('md') previous_device_classes = [ i.class_label for i in device_class.all_smaller] vassert( previous_device_classes == ['xs', 'sm'] ) # Case: when there is no class smaller than given device_class = DeviceClass('xs') previous_device_classes = device_class.all_smaller vassert( previous_device_classes == [] )
def __init__(self, collapse_below_device_class, center_contents=False, fixed_to=None, align_toggle_left=False, collapse_brand_with_content=False, colour_theme=None, bg_scheme=None, text=None): super().__init__(fixed_to=fixed_to, center_contents=center_contents, colour_theme=colour_theme, bg_scheme=bg_scheme) self.collapse_below_device_class = DeviceClass( collapse_below_device_class) self.collapse_brand_with_content = collapse_brand_with_content self.align_toggle_left = align_toggle_left if not self.collapse_below_device_class.one_smaller: raise ProgrammerError( ('There is no device class smaller than %s' % self.collapse_below_device_class) + ' It does not make sense to collapse only ' 'if the viewport is smaller than the smallest device') self.text = text self.collapsing_content = None
def __init__(self, collapse_below_device_class, fixed_to=None, full=False, center_contents=False, colour_theme=None, bg_scheme=None, text=None): super(ResponsiveLayout, self).__init__(fixed_to=fixed_to, full=full, center_contents=center_contents, colour_theme=colour_theme, bg_scheme=bg_scheme) self.collapse_below_device_class = DeviceClass( collapse_below_device_class) if not self.collapse_below_device_class.one_smaller: raise ProgrammerError(('There is no device class smaller than %s' % self.collapse_below_device_class)+\ ' It does not make sense to collapse only if the viewport is smaller than the smallest device') self.text = text
def test_all_device_classes(): """There is a specific list of supported DeviceClasses, in order of device size.""" device_classes = [i.name for i in DeviceClass.all_classes()] assert device_classes == ['xs', 'sm', 'md', 'lg', 'xl']
def all_device_classes(fixture): """There is a specific list of supported DeviceClasses, in order of device size.""" device_classes = [ i.class_label for i in DeviceClass.all_classes()] vassert( device_classes == ['xs', 'sm', 'md', 'lg', 'xl'] )