#!/usr/bin/env python

from nose.tools import *
from utilities import execution_path

import os, sys, glob, mapnik

def setup():
    # All of the paths used are relative, if we run the tests
    # from another directory we need to chdir()
    os.chdir(execution_path('.'))

# We expect these files to not raise any
# exceptions at all
def assert_loads_successfully(file):
    m = mapnik.Map(512, 512)

    strict = True
    mapnik.load_map(m, file, strict)
    
    # libxml2 is not smart about paths, and clips the last directory off
    # of a path if it does not end in a trailing slash
    base_path = os.path.dirname(file) + '/'
    mapnik.load_map_from_string(m,open(file,'rb').read(),strict,base_path)
    

# We expect these files to raise a UserWarning
# and fail if there isn't one (or a different type
# of exception)
@raises(UserWarning)
def assert_raises_userwarning(file):
    m = mapnik.Map(512, 512)

    strict = True
    mapnik.load_map(m, file, strict)

def test_broken_files():
    broken_files = glob.glob("../data/broken_maps/*.xml")

    # Add a filename that doesn't exist 
    broken_files.append("../data/broken/does_not_exist.xml")

    for file in broken_files:
        yield assert_raises_userwarning, file

def test_good_files():
    good_files = glob.glob("../data/good_maps/*.xml")

    for file in good_files:
        yield assert_loads_successfully, file

@@ -743,27 +743,28 @@
 raise a 
-UserWarning
+RuntimeError
 %0A# and f
@@ -835,19 +835,20 @@
 ses(
-UserWarning
+RuntimeError
 )%0Ade
@@ -863,27 +863,29 @@
 _raises_
-userwarning
+runtime_error
 (file):%0A
@@ -1219,19 +1219,21 @@
 ses_
-userwarning
+runtime_error
 , fi

bring tests up to #442 change