Exemplo n.º 1
0
def test_dispatch_when_filesystem_has_been_modified():
    # Create an empty www_root
    www = FilesystemTree()
    # Help the dispatchers that rely on `mtime`
    st = os.stat(www.root)
    os.utime(www.root, (st.st_atime - 10, st.st_mtime - 10))
    # Initialize the dispatchers
    dispatchers = []
    for dispatcher_class in DISPATCHER_CLASSES:
        dispatchers.append(dispatcher_class(
            www_root    = www.root,
            is_dynamic  = lambda n: n.endswith('.spt'),
            indices     = ['index.html'],
            typecasters = {},
        ))
        dispatchers[-1].build_dispatch_tree()
    # Now add an index file and try to dispatch
    www.mk(('index.html', 'Greetings, program!'))
    for dispatcher in dispatchers:
        print("Attempting dispatch with", dispatcher.__class__.__name__)
        result = dispatcher.dispatch('/', [''])
        if dispatcher.__class__.__name__ == 'UserlandDispatcher':
            assert result.status == DispatchStatus.unindexed
            assert result.match == www.root + os.path.sep
        else:
            assert result.status == DispatchStatus.okay
            assert result.match == www.resolve('index.html')
        assert result.wildcards is None
        assert result.extension is None
        assert result.canonical is None
Exemplo n.º 2
0
def test_sd_false_via_constructor():
    try:
        fs = FilesystemTree(should_dedent=False)
        fs.mk(('some/dir/file.txt', '    Greetings, program!'))
        contents = open(fs.resolve('some/dir/file.txt')).read()
        assert contents == '    Greetings, program!'
    finally:
        fs.remove()
Exemplo n.º 3
0
def test_encoding_cp1140_via_constructor():
    try:
        fs = FilesystemTree(encoding='cp1140')
        fs.mk(('file.txt', A_UNICODE))
        contents = open(fs.resolve('file.txt'), 'rb').read()
        assert contents == AS_CP1140
    finally:
        fs.remove()
Exemplo n.º 4
0
def test_encoding_cp1140_via_constructor():
    try:
        fs = FilesystemTree(encoding='cp1140')
        fs.mk(('file.txt', A_UNICODE))
        contents = open(fs.resolve('file.txt'), 'rb').read()
        assert contents == AS_CP1140
    finally:
        fs.remove()
Exemplo n.º 5
0
def test_sd_false_via_constructor():
    try:
        fs = FilesystemTree(should_dedent=False)
        fs.mk(('some/dir/file.txt', '    Greetings, program!'))
        contents = open(fs.resolve('some/dir/file.txt')).read()
        assert contents == '    Greetings, program!'
    finally:
        fs.remove()
Exemplo n.º 6
0
def test_encoding_utf8_via_instance_attribute():
    try:
        fs = FilesystemTree(encoding='cp1140')
        fs.encoding = 'utf8'
        fs.mk(('file.txt', A_UNICODE))
        contents = open(fs.resolve('file.txt'), 'rb').read()
        assert contents == AS_UTF8
    finally:
        fs.remove()
Exemplo n.º 7
0
def test_sd_true_via_instance_attribute():
    try:
        fs = FilesystemTree(should_dedent=False)
        fs.should_dedent = True
        fs.mk(('some/dir/file.txt', '    Greetings, program!'))
        contents = open(fs.resolve('some/dir/file.txt')).read()
        assert contents == 'Greetings, program!'
    finally:
        fs.remove()
Exemplo n.º 8
0
def test_encoding_utf8_via_instance_attribute():
    try:
        fs = FilesystemTree(encoding='cp1140')
        fs.encoding = 'utf8'
        fs.mk(('file.txt', A_UNICODE))
        contents = open(fs.resolve('file.txt'), 'rb').read()
        assert contents == AS_UTF8
    finally:
        fs.remove()
Exemplo n.º 9
0
def test_sd_true_via_instance_attribute():
    try:
        fs = FilesystemTree(should_dedent=False)
        fs.should_dedent = True
        fs.mk(('some/dir/file.txt', '    Greetings, program!'))
        contents = open(fs.resolve('some/dir/file.txt')).read()
        assert contents == 'Greetings, program!'
    finally:
        fs.remove()
Exemplo n.º 10
0
def test_encoding_cp1140_via_class_attribute():
    _reset = FilesystemTree.encoding
    try:
        FilesystemTree.encoding = 'cp1140'
        fs = FilesystemTree()
        fs.mk(('file.txt', A_UNICODE))
        contents = open(fs.resolve('file.txt'), 'rb').read()
        assert contents == AS_CP1140
    finally:
        FilesystemTree.encoding = _reset
        fs.remove()
Exemplo n.º 11
0
def test_encoding_utf8_via_constructor():
    _reset = FilesystemTree.encoding
    try:
        FilesystemTree.encoding = 'cp1140'
        fs = FilesystemTree(encoding='utf8')
        fs.mk(('file.txt', A_UNICODE))
        contents = open(fs.resolve('file.txt'), 'rb').read()
        assert contents == AS_UTF8
    finally:
        FilesystemTree.encoding = _reset
        fs.remove()
Exemplo n.º 12
0
def test_sd_false_via_class_attribute():
    _reset = FilesystemTree.should_dedent
    try:
        FilesystemTree.should_dedent = False
        fs = FilesystemTree()
        fs.mk(('some/dir/file.txt', '    Greetings, program!'))
        contents = open(fs.resolve('some/dir/file.txt')).read()
        assert contents == '    Greetings, program!'
    finally:
        FilesystemTree.should_dedent = _reset
        fs.remove()
Exemplo n.º 13
0
def test_encoding_cp1140_via_class_attribute():
    _reset = FilesystemTree.encoding
    try:
        FilesystemTree.encoding = 'cp1140'
        fs = FilesystemTree()
        fs.mk(('file.txt', A_UNICODE))
        contents = open(fs.resolve('file.txt'), 'rb').read()
        assert contents == AS_CP1140
    finally:
        FilesystemTree.encoding = _reset
        fs.remove()
Exemplo n.º 14
0
def test_encoding_utf8_via_constructor():
    _reset = FilesystemTree.encoding
    try:
        FilesystemTree.encoding = 'cp1140'
        fs = FilesystemTree(encoding='utf8')
        fs.mk(('file.txt', A_UNICODE))
        contents = open(fs.resolve('file.txt'), 'rb').read()
        assert contents == AS_UTF8
    finally:
        FilesystemTree.encoding = _reset
        fs.remove()
Exemplo n.º 15
0
def test_sd_false_via_class_attribute():
    _reset = FilesystemTree.should_dedent
    try:
        FilesystemTree.should_dedent = False
        fs = FilesystemTree()
        fs.mk(('some/dir/file.txt', '    Greetings, program!'))
        contents = open(fs.resolve('some/dir/file.txt')).read()
        assert contents == '    Greetings, program!'
    finally:
        FilesystemTree.should_dedent = _reset
        fs.remove()