Пример #1
0
    def test_match_path_path(self):
        a = make_path("/:NXentry/:NXinstrument/:NXdetector")
        b = make_path("/scan_1:NXentry/p08:NXinstrument/mythen:NXdetector")
        self.assertTrue(match(a,b))

        b.pop_front()
        self.assertTrue(not match(a,b))
        b.push_front("/")
        b.pop_back()
        self.assertTrue(not match(a,b))
Пример #2
0
    def test_add_path(self):
        a = make_path("/:NXentry/:NXinstrument")
        b = make_path(":NXdetector/data")
        c = a+b
        self.assertEqual(c.__str__(),"/:NXentry/:NXinstrument/:NXdetector/data")
        self.assertEqual(a.__str__(),"/:NXentry/:NXinstrument")
        self.assertEqual(b.__str__(),":NXdetector/data")
        
        b.push_front("/:NXroot")
        self.assertRaises(ValueError,a.__add__,b)
        b.pop_front()
        b.filename="test.nxs"
        self.assertRaises(ValueError,a.__add__,b)

        self.assertRaises(TypeError,a.__add__,1)
Пример #3
0
 def test_back(self):
     str_path = "file.nxs://:NXentry/:NXinstrument/data@units"
     p = make_path(str_path)
     
     data = p.back
     self.assertEqual(data["base_class"],"")
     self.assertEqual(data["name"],"data")
     self.assertTrue(has_name(data))
     self.assertTrue(not has_class(data))
Пример #4
0
 def test_front(self):
     str_path = "file.nxs://:NXentry/:NXinstrument/data@units"
     p = make_path(str_path)
     
     root = p.front
     self.assertEqual(root["base_class"],"NXroot")
     self.assertEqual(root["name"],"/")
     self.assertTrue(has_name(p.front))
     self.assertTrue(has_class(p.front))
Пример #5
0
    def test_add_string(self):
        
        a = make_path(":NXentry")
        c = a+":NXinstrument/"
        self.assertEqual(c.__str__(),":NXentry/:NXinstrument")
        c = "/"+a
        self.assertEqual(c.__str__(),"/:NXentry")
        self.assertTrue(is_root_element(c.front))

        a += ":NXinstrument/data"
        self.assertEqual(a.__str__(),":NXentry/:NXinstrument/data")
Пример #6
0
    def test_iteration(self):
        s = ":NXentry/:NXinstrument/:NXdetector/data"
        p_dicts = [{"base_class":"NXentry","name":""},
                   {"base_class":"NXinstrument","name":""},
                   {"base_class":"NXdetector","name":""},
                   {"base_class":"","name":"data"}]
        p = make_path(s)

        self.assertEqual(len(p),4)

        for (ref,e) in zip(p_dicts,p):
            self.assertEqual(ref["name"],e["name"])
            self.assertEqual(ref["base_class"],e["base_class"])
Пример #7
0
    def test_pop_front(self):
        p = make_path(":NXentry/:NXinstrument/:NXdetector/data")

        self.assertEqual(len(p),4)
        p.pop_front()
        self.assertEqual(p.__str__(),":NXinstrument/:NXdetector/data")
        p.pop_front()
        self.assertEqual(p.__str__(),":NXdetector/data")
        p.pop_front()
        self.assertEqual(p.__str__(),"data")
        p.pop_front()
        self.assertEqual(p.__str__(),"")
        self.assertRaises(IndexError,p.pop_front)
Пример #8
0
    def test_pop_back(self):
        p = make_path(":NXentry/:NXinstrument/:NXdetector/data")

        self.assertTrue(not is_root_element(p.front))

        self.assertEqual(len(p),4)
        p.pop_back()
        self.assertEqual(p.__str__(),":NXentry/:NXinstrument/:NXdetector")
        p.pop_back()
        self.assertEqual(p.__str__(),":NXentry/:NXinstrument")
        p.pop_back()
        self.assertEqual(p.__str__(),":NXentry")
        p.pop_back()
        self.assertEqual(p.__str__(),"")
        self.assertRaises(IndexError,p.pop_back)
Пример #9
0
from __future__ import print_function
from pni.io.nx import nxpath
from pni.io.nx import make_path
from pni.io.nx import is_root_element
from pni.io.nx import has_class
from pni.io.nx import has_name

p = make_path("/:NXentry")
entry = p.back
print(entry)
print(has_class(entry))
print(entry)
print(has_name(entry))
print(entry)
Пример #10
0
 def test_attribute(self):
     p = make_path(":NXentry/:NXinstrument@NX_class")
     self.assertTrue(not is_absolute(p))
     self.assertEqual(p.attribute,"NX_class")
     p.attribute="date"
     self.assertEqual(p.attribute,"date")
Пример #11
0
 def test_filename(self):
     p = make_path("file.nxs://:NXentry/:NXinstrument")
     self.assertEqual(p.filename,"file.nxs")
     p.filename="hello.nxs"
     self.assertEqual(p.filename,"hello.nxs")
Пример #12
0
 def test_creation(self):
     str_path = "file.nxs://:NXentry/:NXinstrument/data@units"
     p = make_path(str_path)
     self.assertTrue(is_absolute(p))
     self.assertEqual(p.size,4)
     self.assertEqual(p.__str__(),str_path)
Пример #13
0
    def test_match(self):
        self.assertTrue(match(make_path("/:NXentry/:NXinstrument/:NXdetector"),
                              make_path("/scan_1:NXentry/p08:NXinstrument/mythen:NXdetector")))

        self.assertTrue(match("/:NXentry/:NXinstrument/:NXdetector",
                              "/scan_1:NXentry/p08:NXinstrument/mythen:NXdetector"))