Ejemplo n.º 1
0
    def test_all_images_are_used(self):
        error = False

        for f in self.md_files:
            path = os.path.dirname(os.path.abspath(f))
            if not os.path.exists(path + "/pix"):
                continue

            existing_images = gglob(path, "*.png")  + gglob(path, "*.jpg") +\
                         gglob(path, "*.jpeg") + gglob(path, "*.gif") +\
                         gglob(path, "*.svg")

            mentioned_images = get_grep(cat(f), "!\[\]\(([^)]*)\)")

            for img in mentioned_images:
                full_path = os.path.join(path,
                                         img).replace('/./', '/').replace(
                                             '\./pix/', '\\pix\\')
                if os.path.exists(full_path) and (full_path
                                                  in existing_images):
                    existing_images.remove(full_path)

            if len(existing_images) > 0:
                print("images are not used: ")
                for i in existing_images:
                    print('      - {}'.format(i))
                error = True

        self.assertEqual(False, error)
Ejemplo n.º 2
0
    def test_all_images_are_used(self):
        error = False

        for f in self.md_files:
            path = os.path.dirname(os.path.abspath(f))
            if not os.path.exists(path + "/pix"):
                continue

            existing_images = gglob(path, "*.png")  + gglob(path, "*.jpg") +\
                         gglob(path, "*.jpeg") + gglob(path, "*.gif") +\
                         gglob(path, "*.svg")

            mentioned_images = get_grep(cat(f), "!\[\]\(([^)]*)\)")

            for img in mentioned_images:
                full_path = os.path.join(path, img).replace('/./', '/')
                if os.path.exists(full_path) and (full_path in existing_images):
                    existing_images.remove(full_path)

            if len(existing_images) > 0:
                print("images are not used: ")
                for i in existing_images:
                    print('      - {}'.format(i))
                error = True

        self.assertEqual(False, error)
Ejemplo n.º 3
0
def check_all_file_size(max_size):
    print_caller_name()
    error = False
    global root
    files = gglob(root, "*")
    for f in files:
        if not check_size(f, max_size):
            print('error: sizeof({}) >= {}'.format(f, max_size))
            error = True
    return error
Ejemplo n.º 4
0
def check_empty_line_before_eof():
    print_caller_name()
    error = False
    global root
    files = gglob(root, "*.md")
    for f in files:
        if cat(f)[-1][-1] != '\n':
            print('error: in {} has no line break in the end of file'.format(f))
            error = True
    return error
Ejemplo n.º 5
0
    def test_all_file_size(self):
        error = False

        files = gglob(self.root, "*")
        for f in files:
            if not os.path.getsize(f) < self.MAX_FILE_SIZE:
                print('error: sizeof({}) >= {}'.format(f, self.MAX_FILE_SIZE))
                error = True

        self.assertEqual(False, error)
Ejemplo n.º 6
0
def check_no_trailing_spaces():
    print_caller_name()
    error = False
    global root
    files = gglob(root, "*.md")
    for f in files:
        lines = grep(cat(f), ".*[ ]+$")
        if len(lines) > 0:
            print('error: in {} has space in the end of lines {}'.format(f, lines))
            error = True
    return error
Ejemplo n.º 7
0
def check_no_tabs():
    print_caller_name()
    error = False
    global root
    files = gglob(root, "*.md")
    for f in files:
        lines = grep(cat(f), "\t")
        if len(lines) > 0:
            print('error: in {} has tabs in {} lines'.format(f, lines))
            error = True
    return error
Ejemplo n.º 8
0
    def test_all_file_size(self):
        error = False

        files = gglob(self.root, "*")
        files = [f for f in files if os.path.splitext(f)[1] != ".pdf"]

        for f in files:
            if not os.path.getsize(f) < self.MAX_FILE_SIZE:
                print('Error: size of {} >= {}'.format(f, self.MAX_FILE_SIZE))
                error = True

        self.assertEqual(False, error)
Ejemplo n.º 9
0
def check_all_images_are_used():
    print_caller_name()
    error = False
    global root

    files = gglob(root, "*.md")
    for f in files:
        path = os.path.dirname(os.path.abspath(f))
        if not os.path.exists(path + "/pix"):
            continue

        existing_images = gglob(path, "*.png")  + gglob(path, "*.jpg") +\
                     gglob(path, "*.jpeg") + gglob(path, "*.gif") +\
                     gglob(path, "*.svg")

        mentioned_images = get_grep(cat(f), "!\[\]\(([^)]*)\)")

        for img in mentioned_images:
            full_path = os.path.join(path, img).replace('/./', '/')
            if os.path.exists(full_path) and (full_path in existing_images):
                existing_images.remove(full_path)

        if len(existing_images) > 0:
            print("images are not used: ")
            for i in existing_images:
                print('      - {}'.format(i))
            error = True  # TODO: change to Truem so check fails

    return error
Ejemplo n.º 10
0
def check_all_images_exist():
    print_caller_name()
    error = False
    global root
    files = gglob(root, "*.md")
    for f in files:
        path = os.path.dirname(os.path.abspath(f))
        m = get_grep(cat(f), "!\[\]\(([^)]*)\)")
        for img in m:
            full_path = os.path.join(path, img).replace('/./', '/')
            if not os.path.exists(full_path):
                print('error: {} does not exist'.format(full_path))
                error = True
    return error
def extract_files_with_control_questions():
    files = gglob("./", "*.md")
    # print("Full list of files found:")
    # print("\n - ".join(files))

    groups = split_into_groups(files)

    if len(groups[0]):
        print("These files do not contain control questions:")
        print(" - " + "\n - ".join(groups[0]))
    if len(groups[2]):
        print("These files have multiple questions:")
        print(" - " + "\n - ".join(groups[2]))

    return sorted(groups[1])
Ejemplo n.º 12
0
def check_use_highlighting():
    print_caller_name()
    error = False
    global root
    files = gglob(root, "*.md")
    for f in files:
        p = re.compile(".*```\n[^`]*```\n.*")
        text = ''.join(cat(f))
        m = p.findall(text)
        if m:
            print('error: {} has block code without highlighting:'.format(f))
            for b in m:
                print('\n{}\n'.format(b))
            error = True
    return error
def extract_files_with_control_questions():
    files = gglob("./", "*.md")
    # print("Full list of files found:")
    # print("\n - ".join(files))

    groups = split_into_groups(files)

    if len(groups[0]):
        print("These files do not contain control questions:")
        print(" - " + "\n - ".join(groups[0]))
    if len(groups[2]):
        print("These files have multiple questions:")
        print(" - " + "\n - ".join(groups[2]))

    return sorted(groups[1])
Ejemplo n.º 14
0
 def setUp(self):
     toplevel = subprocess.getoutput('git rev-parse --show-toplevel')
     self.root = os.path.join(toplevel, 'slides')
     self.MAX_FILE_SIZE = 2500 * 1024
     self.md_files = gglob(self.root, "*.md")
Ejemplo n.º 15
0
 def setUp(self):
     toplevel = subprocess.getoutput('git rev-parse --show-toplevel')
     self.root = os.path.join(toplevel, 'slides')
     self.MAX_FILE_SIZE = 2500 * 1024
     self.md_files = gglob(self.root, "*.md")