import os
from unittest import TestCase
from tempfile import mkstemp, mkdtemp

import xattr

class TestFile(TestCase):
    def setUp(self):
        self.tempfh, self.tempfile = mkstemp()

    def tearDown(self):
        os.close(self.tempfh)
        os.unlink(self.tempfile)

    def testAttr(self):
        x = xattr.xattr(self.tempfile)
        self.assertEqual(x.keys(), [])
        self.assertEqual(dict(x), {})

        x['sopal'] = 'foo'
        x['sop.foo'] = 'bar'
        del x

        x = xattr.xattr(self.tempfile)
        self.assertTrue('sopal' in x)
        self.assertEqual(x['sopal'], 'foo')
        self.assertTrue('sop.foo' in x)
        self.assertEqual(x['sop.foo'], 'bar')

        del x['sop.foo']
        del x
        
        x = xattr.xattr(self.tempfile)
        self.assertTrue('sop.foo' not in x)


class TestDir(TestFile):
    def setUp(self):
        self.tempfile = mkdtemp()
    
    def tearDown(self):
        os.rmdir(self.tempfile)
@@ -421,16 +421,21 @@
      x%5B'
+user.
 sopal'%5D 
@@ -449,24 +449,29 @@
 %0A        x%5B'
+user.
 sop.foo'%5D = 
@@ -555,16 +555,21 @@
 rtTrue('
+user.
 sopal' i
@@ -601,16 +601,21 @@
 qual(x%5B'
+user.
 sopal'%5D,
@@ -639,32 +639,37 @@
 elf.assertTrue('
+user.
 sop.foo' in x)%0A 
@@ -695,16 +695,21 @@
 qual(x%5B'
+user.
 sop.foo'
@@ -734,16 +734,21 @@
  del x%5B'
+user.
 sop.foo'
@@ -836,16 +836,21 @@
 rtTrue('
+user.
 sop.foo'
@@ -986,24 +986,25 @@
  os.rmdir(self.tempfile)
+%0A

use user.* prefixed properties to pass tests on linux