# Path: sigal/utils.py
# VIDEO_MIMES = {'.mp4': 'video/mp4', '.webm': 'video/webm', '.ogv': 'video/ogg'}
# MD = None
#         MD = Markdown(
#             extensions=[
#                 'markdown.extensions.extra',
#                 'markdown.extensions.meta',
#                 'markdown.extensions.tables',
#             ],
#             output_format='html5',
#         )
# class Devnull:
#     def write(self, *_):
#     def flush(self, *_):
# def copy(src, dst, symlink=False, rellink=False):
# def check_or_create_dir(path):
# def get_mod_date(path):
# def url_from_path(path):
# def read_markdown(filename):
# def is_valid_html5_video(ext):
# def get_mime(ext):


import os
from pathlib import Path
from sigal import utils


def test_check_or_create_dir(tmpdir):
    path = str(tmpdir.join('new_directory'))
    utils.check_or_create_dir(path)
    assert os.path.isdir(path)


def test_url_from_path():
    assert utils.url_from_path(os.sep.join(['foo', 'bar'])) == 'foo/bar'


def test_url_from_windows_path(monkeypatch):
    monkeypatch.setattr('os.sep', "\\")
    path = os.sep.join(['foo', 'bar'])
    assert path == r'foo\bar'
    assert utils.url_from_path(path) == 'foo/bar'


def test_read_markdown():
    src = os.path.join(SAMPLE_DIR, 'pictures', 'dir1', 'test1', '11.md')
    m = utils.read_markdown(src)
    assert m['title'] == "Foo Bar"
    assert m['meta']['location'][0] == "Bavaria"
    assert m['description'] == "<p>This is a funny description of this image</p>"


def test_read_markdown_empty_file(tmpdir):
    src = tmpdir.join("file.txt")
    src.write("content")

# Path: sigal/utils.py
# VIDEO_MIMES = {'.mp4': 'video/mp4', '.webm': 'video/webm', '.ogv': 'video/ogg'}
# MD = None
#         MD = Markdown(
#             extensions=[
#                 'markdown.extensions.extra',
#                 'markdown.extensions.meta',
#                 'markdown.extensions.tables',
#             ],
#             output_format='html5',
#         )
# class Devnull:
#     def write(self, *_):
#     def flush(self, *_):
# def copy(src, dst, symlink=False, rellink=False):
# def check_or_create_dir(path):
# def get_mod_date(path):
# def url_from_path(path):
# def read_markdown(filename):
# def is_valid_html5_video(ext):
# def get_mime(ext):


# Path: tests/test_utils.py
import os
from pathlib import Path
from sigal import utils



def test_check_or_create_dir(tmpdir):
    path = str(tmpdir.join('new_directory'))
    utils.check_or_create_dir(path)
    assert os.path.isdir(path)


def test_url_from_path():
    assert utils.url_from_path(os.sep.join(['foo', 'bar'])) == 'foo/bar'


def test_url_from_windows_path(monkeypatch):
    monkeypatch.setattr('os.sep', "\\")
    path = os.sep.join(['foo', 'bar'])
    assert path == r'foo\bar'
    assert utils.url_from_path(path) == 'foo/bar'


def test_read_markdown():
    src = os.path.join(SAMPLE_DIR, 'pictures', 'dir1', 'test1', '11.md')
    m = utils.read_markdown(src)
    assert m['title'] == "Foo Bar"
    assert m['meta']['location'][0] == "Bavaria"
    assert m['description'] == "<p>This is a funny description of this image</p>"


def test_read_markdown_empty_file(tmpdir):
    src = tmpdir.join("file.txt")
    src.write("content")

    m = utils.read_markdown(str(src))