def test_with_wrong_type(input_file, error_type):
    """Make sure when user give a wrong type arg, raise TypeError"""
    with pytest.raises(TypeError) as exc_info:
        utils.get_static_file(input_file)

    exception_msg = exc_info.value.args[0]
    assert exception_msg == "Input argument 'path' should be basestring type, " \
                            "but get <type '{}'>".format(error_type)
Exemplo n.º 2
0
 def __call__(self, path, color=None):
     from dayu_widgets3 import utils
     full_path = utils.get_static_file(path)
     if full_path is None:
         return self.cls()
     key = u'{}{}'.format(full_path.lower(), color or '')
     pix_map = self._cache_pix_dict.get(key, None)
     if pix_map is None:
         if full_path.endswith('svg'):
             pix_map = self._render_svg(full_path, color)
         else:
             pix_map = self.cls(full_path)
         self._cache_pix_dict.update({key: pix_map})
     return pix_map
def test_custom_static_folder(custom_folder):
    """Test when user append a custom static folder."""
    CUSTOM_STATIC_FOLDERS.append(str(custom_folder))
    for input_file, result in (
        ('add_line.svg', os.path.join(DEFAULT_STATIC_FOLDER, 'add_line.svg')),
        ('check.svg', os.path.join(DEFAULT_STATIC_FOLDER, 'check.svg')),
        ('', None),
        ('a_not_exists_file', None),
        (
            os.path.join(os.path.dirname(__file__), 'for_test.txt'),
            # user give a full path file, return
            os.path.join(os.path.dirname(__file__), 'for_test.txt')),
        ('sub_folder/sub_file.png',
         os.path.join(str(custom_folder), 'sub_folder/sub_file.png')),
    ):
        assert utils.get_static_file(input_file) == result
Exemplo n.º 4
0
    def __init__(self, theme='light', primary_color=None):
        super(MTheme, self).__init__()
        default_qss_file = utils.get_static_file('main.qss')
        with open(default_qss_file, 'r') as f:
            self.default_qss = QssTemplate(f.read())
        self.primary_color, self.item_hover_bg = (None, None)
        self.primary_1, self.primary_2, self.primary_3, self.primary_4, self.primary_5, = (
            None, None, None, None, None)
        self.primary_6, self.primary_7, self.primary_8, self.primary_9, self.primary_10 = (
            None, None, None, None, None)

        self._init_color()
        self.set_primary_color(primary_color or MTheme.blue)
        self.set_theme(theme)
        self._init_font()
        self._init_size()
        self.unit = 'px'
        self.default_size = self.medium

        self.text_error_color = self.error_7
        self.text_color_inverse = "#fff"
        self.text_warning_color = self.warning_7
def test_get_static_file(input_path, output_path):
    """Only default static file. Test different situation input."""
    assert utils.get_static_file(input_path) == output_path