コード例 #1
0
def test_data_ufo_ufo2_get_glyphsdir_pathlist():
    ufoobj = Ufo2(test_ufopath, test_glyphs_dirlist_2)

    pathlist = ufoobj.get_glyphsdir_path_list()
    assert isinstance(pathlist, list)
    assert len(pathlist) == 1
    assert pathlist[0] == glyphs_dir_list_v2
コード例 #2
0
def test_data_ufo_ufo2_class_instantiation():
    ufoobj = Ufo2(test_ufopath, test_glyphs_dirlist_2)

    assert ufoobj.ufopath == "Test-Regular.ufo"
    assert ufoobj.glyphsdir_list == test_glyphs_dirlist_2
    assert ufoobj.mandatory_root_basefilepaths == ['metainfo.plist']
    assert ufoobj.mandatory_glyphsdir_basefilepaths == ['contents.plist']
コード例 #3
0
def test_ufolint_validators_images_ufo2_success():
    """
    UFOv2 does not include images dir as part of spec.  When missing, returns empty list of failures
    """
    ufoobj = Ufo2(ufo2_test_success_path, test_glyphs_dirlist_v2)
    fail_list = run_all_images_validations(ufoobj)
    assert isinstance(fail_list, list)
    assert len(fail_list) == 0
コード例 #4
0
def test_data_ufo_ufo3_make_glyphsdir_plist_path():
    glyphsdirname = "glyphs"
    ufoobj = Ufo2(test_ufopath, test_glyphs_dirlist_3)

    assert ufoobj._make_glyphsdir_plist_path(
        glyphsdirname, 'contents.plist') == contents_plist_path_1
    assert ufoobj._make_glyphsdir_plist_path(
        glyphsdirname, 'layerinfo.plist') == layerinfo_plist_path_1
コード例 #5
0
def test_data_ufo_ufo2_get_mandatory_filepaths_list():
    ufoobj = Ufo2(test_ufopath, test_glyphs_dirlist_2)

    res_list = ufoobj.get_mandatory_filepaths_list()
    assert isinstance(res_list, list)
    assert len(res_list) == 2
    for filepath in res_list:
        assert (filepath in mandatory_list_v2) is True
    assert (fontinfo_plist_path in res_list) is False
コード例 #6
0
def test_data_ufo_ufo2_get_glyphsdir_plist_filepath_list():
    ufoobj = Ufo2(test_ufopath, test_glyphs_dirlist_2)

    assert isinstance(
        ufoobj.get_glyphsdir_plist_filepath_list('contents.plist'),
        list) is True
    assert len(ufoobj.get_glyphsdir_plist_filepath_list('contents.plist')) == 1
    assert ufoobj.get_glyphsdir_plist_filepath_list(
        'contents.plist')[0] == contents_plist_path_1
コード例 #7
0
def test_data_ufo_ufo2_make_root_plist_path():
    ufoobj = Ufo2(test_ufopath, test_glyphs_dirlist_2)

    assert ufoobj._make_root_plist_path(
        'metainfo.plist') == metainfo_plist_path
    assert ufoobj._make_root_plist_path(
        'fontinfo.plist') == fontinfo_plist_path
    assert ufoobj._make_root_plist_path('groups.plist') == groups_plist_path
    assert ufoobj._make_root_plist_path('kerning.plist') == kerning_plist_path
    assert ufoobj._make_root_plist_path('lib.plist') == lib_plist_path
コード例 #8
0
def test_data_ufo_ufo3_get_root_plist_filepath():
    ufoobj = Ufo2(test_ufopath, test_glyphs_dirlist_3)

    assert ufoobj.get_root_plist_filepath(
        'metainfo.plist') == metainfo_plist_path
    assert ufoobj.get_root_plist_filepath(
        'fontinfo.plist') == fontinfo_plist_path
    assert ufoobj.get_root_plist_filepath('groups.plist') == groups_plist_path
    assert ufoobj.get_root_plist_filepath(
        'kerning.plist') == kerning_plist_path
    assert ufoobj.get_root_plist_filepath('lib.plist') == lib_plist_path
    assert ufoobj.get_root_plist_filepath(
        'layercontents.plist') == layercontents_plist_path
コード例 #9
0
 def __init__(self, ufopath, ufoversion, glyphs_dir_list):
     self.ufopath = ufopath
     self.ufoversion = ufoversion
     self.glyphs_dir_list = glyphs_dir_list
     self.testfile = None
     if self.ufoversion == 2:
         self.ufoobj = Ufo2(self.ufopath, self.glyphs_dir_list)
     elif self.ufoversion == 3:
         self.ufoobj = Ufo3(self.ufopath, self.glyphs_dir_list)
     self.root_plist_list = self.ufoobj.all_root_plist_files_list
     self.glyphsdir_plist_list = self.ufoobj.all_glyphsdir_plist_files_list
     self.mandatory_filepaths_list = self.ufoobj.get_mandatory_filepaths_list()
     self.test_fail_list = []
コード例 #10
0
def test_data_ufo_ufo2_get_ufo_version():
    ufoobj = Ufo2(test_ufopath, test_glyphs_dirlist_2)

    version = ufoobj.get_ufo_version()
    assert version == 2
コード例 #11
0
    def run(self):
        # Print UFO filepath header
        print(" ")
        print('~' * len(self.ufopath))
        print(self.ufopath)
        print('~' * len(self.ufopath))
        print(" ")

        # [START] EARLY FAIL TESTS ----------------------------------------------------------------
        #      UFO directory filepath
        #      .ufo directory extension
        #      import with ufoLib
        #      version check
        #      ufo obj define
        #        v3 only: presence of layercontents.plist to define the glyphs directories in source
        #        v2 only: no layercontents.plist, define as single glyphs directory
        ss = StdStreamer(self.ufopath)
        ss.stream_testname("UFO directory")
        self._check_ufo_dir_path_exists(
        )  # tests user defined UFO directory path
        self._check_ufo_dir_extension(
        )  # tests for .ufo extension on directory
        self._check_metainfo_plist_exists(
        )  # confirm presence of metainfo.plist to define UFO version
        self._validate_read_data_types_metainfo_plist(
        )  # validate the version data type as integer (workaround for bug in ufoLib)
        self._check_ufo_import_and_define_ufo_version(
        )  # confirm ufoLib can import directory. defines UFOReader object as class property
        if self.ufoversion == 3:
            self._check_layercontents_plist_exists(
            )  # tests for presence of a layercontents.plist in root of UFO
            self._validate_read_load_glyphsdirs_layercontents_plist(
            )  # validate layercontents.plist xml and load glyphs dirs
        elif self.ufoversion == 2:
            self.ufo_glyphs_dir_list = [[
                'public.default', 'glyphs'
            ]]  # define as single glyphs directory for UFOv2
        else:  # pragma nocoverage fail if unsupported UFO version (ufolint fail in case behind released UFO version)
            sys.stderr.write(os.linesep + "[ufolint] UFO v" + self.ufoversion +
                             " is not supported in ufolint" + os.linesep)
            sys.exit(1)
        print(" ")
        print("   Found UFO v" + str(self.ufoversion))
        print("   Detected glyphs directories: ")
        for glyphs_dir in self.ufo_glyphs_dir_list:
            # TODO: add glyphs directory validation here : confirm naming = 'glyphs.*'
            sys.stdout.write(
                "     -- " + glyphs_dir[1] +
                " ")  # display the name of the specified glyphs dirs
            res = Result(glyphs_dir[1])
            if dir_exists(os.path.join(self.ufopath, glyphs_dir[1])
                          ):  # test for presence of specified glyphs dir
                res.test_failed = False
                ss.stream_result(res)
            else:
                res.test_failed = True
                res.exit_failure = True
                res.test_long_stdstream_string = "Unable to find the UFO directory '" + glyphs_dir[
                    1] + "' defined in layercontents.plist"
                ss.stream_result(res)
            print(" ")

        # create Ufo objects for subsequent tests - all Ufo object dependent tests must take place below this level
        if self.ufoversion == 2:
            self.ufoobj = Ufo2(self.ufopath, self.ufo_glyphs_dir_list)
        elif self.ufoversion == 3:
            self.ufoobj = Ufo3(self.ufopath, self.ufo_glyphs_dir_list)

        # [START] Mandatory file path tests
        ss.stream_testname("UFO v" + str(self.ufoversion) + " mandatory files")

        mandatory_file_list = self.ufoobj.get_mandatory_filepaths_list()
        for mandatory_file in mandatory_file_list:
            res = Result(mandatory_file)
            if file_exists(mandatory_file):
                res.test_failed = False
                ss.stream_result(res)
            else:
                res.test_failed = True
                res.exit_failure = True
                res.test_long_stdstream_string = mandatory_file + " was not found in " + self.ufopath
                ss.stream_result(res)
        print(" ")
        # [END] Mandatory file path tests
        # [END] EARLY FAIL TESTS ----------------------------------------------------------------

        # [START] XML VALIDATION TESTS  -----------------------------------------------------------
        ss.stream_testname("XML formatting")
        meta_val = MetainfoPlistValidator(self.ufopath, self.ufoversion,
                                          self.ufo_glyphs_dir_list)
        fontinfo_val = FontinfoPlistValidator(self.ufopath, self.ufoversion,
                                              self.ufo_glyphs_dir_list)
        groups_val = GroupsPlistValidator(self.ufopath, self.ufoversion,
                                          self.ufo_glyphs_dir_list)
        kerning_val = KerningPlistValidator(self.ufopath, self.ufoversion,
                                            self.ufo_glyphs_dir_list)
        lib_val = LibPlistValidator(self.ufopath, self.ufoversion,
                                    self.ufo_glyphs_dir_list)
        contents_val = ContentsPlistValidator(self.ufopath, self.ufoversion,
                                              self.ufo_glyphs_dir_list)
        layercont_val = LayercontentsPlistValidator(self.ufopath,
                                                    self.ufoversion,
                                                    self.ufo_glyphs_dir_list)
        layerinfo_val = LayerinfoPlistValidator(self.ufopath, self.ufoversion,
                                                self.ufo_glyphs_dir_list)

        # excute validations, returns list of failure Result() objects
        mv_xml_fail_list = meta_val.run_xml_validation()
        fi_xml_fail_list = fontinfo_val.run_xml_validation()
        g_xml_fail_list = groups_val.run_xml_validation()
        k_xml_fail_list = kerning_val.run_xml_validation()
        l_xml_fail_list = lib_val.run_xml_validation()
        c_xml_fail_list = contents_val.run_xml_validation()
        lc_xml_fail_list = layercont_val.run_xml_validation()
        li_xml_fail_list = layerinfo_val.run_xml_validation()

        # xml validations return lists of all failures, append these to the class failures_list Python list
        for thelist in (mv_xml_fail_list, fi_xml_fail_list, g_xml_fail_list,
                        k_xml_fail_list, l_xml_fail_list, c_xml_fail_list,
                        lc_xml_fail_list, li_xml_fail_list):
            for failed_test_result in thelist:
                self.failures_list.append(failed_test_result)
        print(" ")
        # [END] XML VALIDATION TESTS  --------------------------------------------------------------

        # [START] plist FILE VALIDATION TESTS (includes numerous ufoLib library validations on plist file reads)
        ss.stream_testname("*.plist spec")
        mv_ufolib_import_fail_list = meta_val.run_ufolib_import_validation()
        fi_ufolib_import_fail_list = fontinfo_val.run_ufolib_import_validation(
        )
        g_ufolib_import_fail_list = groups_val.run_ufolib_import_validation()
        k_ufolib_import_fail_list = kerning_val.run_ufolib_import_validation()
        l_ufolib_import_fail_list = lib_val.run_ufolib_import_validation()
        c_ufolib_import_fail_list = contents_val.run_ufolib_import_validation()
        lc_ufolib_import_fail_list = layercont_val.run_ufolib_import_validation(
        )
        li_ufolib_import_fail_list = layerinfo_val.run_ufolib_import_validation(
        )

        for thelist in (mv_ufolib_import_fail_list, fi_ufolib_import_fail_list,
                        g_ufolib_import_fail_list, k_ufolib_import_fail_list,
                        l_ufolib_import_fail_list, c_ufolib_import_fail_list,
                        lc_ufolib_import_fail_list,
                        li_ufolib_import_fail_list):
            for failed_test_result in thelist:
                self.failures_list.append(failed_test_result)

        # [END] plist FILE VALIDATION TESTS

        # [START] features.fea TESTS
        print(" ")
        ss.stream_testname("features.fea")
        ff_path = os.path.join(self.ufopath, 'features.fea')
        res = Result(ff_path)
        if file_exists(ff_path):
            res.test_failed = False
            ss.stream_result(res)
        else:
            sys.stdout.write(
                "not present")  # not a mandatory file, not a failure
        # [END] features.fea TESTS

        # [START] DATA DIRECTORY TESTS - no fails in these tests, reporting only
        if self.ufoversion == 3:  # UFOv3+ only
            print(" ")
            ss.stream_testname("data")
            data_dir_path = os.path.join(self.ufopath, 'data')

            if dir_exists(data_dir_path):
                ufo_reader = UFOReader(self.ufopath)
                raw_data_list = ufo_reader.getDataDirectoryListing()
                data_list = []
                for item in raw_data_list:
                    if not item[
                            0] == ".":  # eliminate dotfiles picked up by the ufoLib method (e.g. .DS_Store on OSX)
                        data_list.append(item)
                if len(data_list) == 0:
                    sys.stdout.write("empty")
                else:
                    sys.stdout.write(str(len(data_list)) + " data files")
            else:
                sys.stdout.write(
                    "not present")  # not a mandatory directory, not a failure
        # [END] DATA DIRECTORY TESTS

        # [START] IMAGES DIRECTORY TESTS
        if self.ufoversion == 3:  # UFO v3+ only
            print(" ")
            ss.stream_testname("images")
            images_dir_path = os.path.join(self.ufopath, 'images')

            if dir_exists(images_dir_path):
                images_dir_failures = run_all_images_validations(self.ufoobj)
                for images_failure_result in images_dir_failures:
                    self.failures_list.append(images_failure_result)
            else:
                sys.stdout.write(
                    "not present")  # not a mandatory directory, not a failure
        # [END] IMAGES DIRECTORY TESTS

        # [START] *.glif VALIDATION TESTS
        print(" ")
        ss.stream_testname("*.glif spec")
        glif_validation_failures = run_all_glif_validations(self.ufoobj)
        for glif_failure_result in glif_validation_failures:
            self.failures_list.append(glif_failure_result)
        # [END] *.glif VALIDATION TESTS

        # TESTS COMPLETED --------------------------------------------------------------------------
        #   stream all failure results as a newline delimited list to user and exit with status code 1
        #   if failures are present, status code 0 if failures are not present
        ss = StdStreamer(self.ufopath)
        ss.stream_final_failures(self.failures_list)
コード例 #12
0
def test_validators_glif_ufo2_run_all_glif_validations_ufolib_import_fail():
    fail_ufo = os.path.join(glif_fail_dir, 'UFO2-UFOlibError.ufo')
    ufoobj = Ufo2(fail_ufo, ufo2_dir_list)
    failure_list = run_all_glif_validations(ufoobj)
    assert len(failure_list) == 1
コード例 #13
0
def test_validators_glif_ufo2_run_all_glif_validations_missing_glif_fail():
    fail_ufo = os.path.join(glif_fail_dir, 'UFO2-MissingGlif.ufo')
    ufoobj = Ufo2(fail_ufo, ufo2_dir_list)
    failure_list = run_all_glif_validations(ufoobj)
    assert len(failure_list) == 1
コード例 #14
0
def test_validators_glif_ufo2_run_all_glif_validations_success():
    ufoobj = Ufo2(ufo2_test_success_path, ufo2_dir_list)
    failure_list = run_all_glif_validations(ufoobj)
    assert isinstance(failure_list, list)
    assert len(failure_list) == 0   # no failures detected