import os, sys; sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

import codecs

import pytest

from lasio import read

egfn = lambda fn: os.path.join(os.path.dirname(__file__), "examples", fn)

def test_utf8_default():
    fn = egfn("sample_extended_chars_utf8.las")
    l = read(fn)

def test_utf8wbom_default():
    fn = egfn("sample_extended_chars_utf8wbom.las")
    l = read(fn)

# The below test fails on Python 3.2+, but works on Python 2.6 and 2.7. Such is life!

# def test_cp1252_default():
#     fn = egfn("sample_extended_chars_cp1252.las")
#     l = read(fn)

def test_utf8_autodetect():
    fn = egfn("sample_extended_chars_utf8.las")
    l = read(fn, autodetect_encoding=True)

def test_utf8wbom_autodetect():
    fn = egfn("sample_extended_chars_utf8wbom.las")
    l = read(fn, autodetect_encoding=True)

def test_cp1252_autodetect():
    fn = egfn("sample_extended_chars_cp1252.las")
    l = read(fn, autodetect_encoding=True)

def test_utf8_encoding_specified():
    fn = egfn("sample_extended_chars_utf8.las")
    l = read(fn, encoding="utf-8")

def test_utf8wbom_encoding_specified():
    fn = egfn("sample_extended_chars_utf8wbom.las")
    l = read(fn, encoding="utf-8-sig")

def test_cp1252_encoding_specified():
    fn = egfn("sample_extended_chars_cp1252.las")
    l = read(fn, encoding="cp1252")


@@ -285,32 +285,242 @@
   l = read(fn)%0A%0A
+# The below tests are failing bizarrely with 266f981, which%0A# should not affect encodings in any way whatsoever - it's %0A# merely using the self.data array (read in via numpy) to%0A# create a pandas.DataFrame.%0A%0A# 
 def test_utf8wbo
@@ -524,32 +524,34 @@
 wbom_default():%0A
+# 
     fn = egfn(%22s
@@ -578,32 +578,34 @@
 _utf8wbom.las%22)%0A
+# 
     l = read(fn)
@@ -598,32 +598,34 @@
   l = read(fn)%0A%0A
+# 
 # The below test
@@ -695,16 +695,18 @@
  life!%0A%0A
+# 
 # def te
@@ -719,32 +719,34 @@
 252_default():%0A#
+ #
      fn = egfn(%22
@@ -773,32 +773,34 @@
 s_cp1252.las%22)%0A#
+ #
      l = read(fn
@@ -798,24 +798,26 @@
 = read(fn)%0A%0A
+# 
 def test_utf
@@ -824,32 +824,34 @@
 8_autodetect():%0A
+# 
     fn = egfn(%22s
@@ -874,32 +874,34 @@
 hars_utf8.las%22)%0A
+# 
     l = read(fn,
@@ -920,32 +920,34 @@
 encoding=True)%0A%0A
+# 
 def test_utf8wbo
@@ -954,32 +954,34 @@
 m_autodetect():%0A
+# 
     fn = egfn(%22s
@@ -1008,32 +1008,34 @@
 _utf8wbom.las%22)%0A
+# 
     l = read(fn,
@@ -1054,32 +1054,34 @@
 encoding=True)%0A%0A
+# 
 def test_cp1252_
@@ -1090,24 +1090,26 @@
 todetect():%0A
+# 
     fn = egf
@@ -1138,32 +1138,34 @@
 rs_cp1252.las%22)%0A
+# 
     l = read(fn,
@@ -1192,16 +1192,18 @@
 =True)%0A%0A
+# 
 def test
@@ -1222,32 +1222,34 @@
 ng_specified():%0A
+# 
     fn = egfn(%22s
@@ -1272,32 +1272,34 @@
 hars_utf8.las%22)%0A
+# 
     l = read(fn,
@@ -1314,24 +1314,26 @@
 g=%22utf-8%22)%0A%0A
+# 
 def test_utf
@@ -1352,32 +1352,34 @@
 ng_specified():%0A
+# 
     fn = egfn(%22s
@@ -1410,24 +1410,26 @@
 8wbom.las%22)%0A
+# 
     l = read
@@ -1456,16 +1456,18 @@
 -sig%22)%0A%0A
+# 
 def test
@@ -1492,24 +1492,26 @@
 pecified():%0A
+# 
     fn = egf
@@ -1544,24 +1544,26 @@
 p1252.las%22)%0A
+# 
     l = read

Disable encoding tests