2012-11-26 07:32:01 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2015-06-25 12:02:52 +00:00
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
2015-02-05 15:56:24 +00:00
|
|
|
|
|
|
|
from pungi.pathmatch import PathMatch, head_tail_split
|
2012-11-26 07:32:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestHeadTailSplit(unittest.TestCase):
|
|
|
|
def test_1(self):
|
|
|
|
head, tail = head_tail_split("a")
|
|
|
|
self.assertEqual(head, "a")
|
|
|
|
self.assertEqual(tail, None)
|
|
|
|
|
|
|
|
head, tail = head_tail_split("/*")
|
|
|
|
self.assertEqual(head, "*")
|
|
|
|
self.assertEqual(tail, None)
|
|
|
|
|
|
|
|
head, tail = head_tail_split("///*")
|
|
|
|
self.assertEqual(head, "*")
|
|
|
|
self.assertEqual(tail, None)
|
|
|
|
|
|
|
|
head, tail = head_tail_split("///*//")
|
|
|
|
self.assertEqual(head, "*")
|
|
|
|
self.assertEqual(tail, None)
|
|
|
|
|
|
|
|
head, tail = head_tail_split("///*//-")
|
|
|
|
self.assertEqual(head, "*")
|
|
|
|
self.assertEqual(tail, "-")
|
|
|
|
|
|
|
|
|
|
|
|
class TestPathMatch(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.pm = PathMatch()
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
self.pm["/*"] = "/star1"
|
2015-06-25 12:02:52 +00:00
|
|
|
self.assertEqual(list(self.pm._final_patterns.keys()), ["*"])
|
2012-11-26 07:32:01 +00:00
|
|
|
self.assertEqual(self.pm._values, [])
|
|
|
|
self.assertEqual(self.pm._final_patterns["*"]._values, ["/star1"])
|
|
|
|
self.assertEqual(sorted(self.pm["/lib"]), ["/star1"])
|
|
|
|
|
|
|
|
self.pm["/*"] = "/star2"
|
|
|
|
self.assertEqual(sorted(self.pm["/lib"]), ["/star1", "/star2"])
|
|
|
|
|
|
|
|
self.pm["/lib"] = "/lib"
|
|
|
|
self.assertEqual(sorted(self.pm["/lib"]), ["/lib", "/star1", "/star2"])
|
|
|
|
|
|
|
|
self.pm["/lib64"] = "/lib64"
|
|
|
|
self.assertEqual(sorted(self.pm["/lib64"]), ["/lib64", "/star1", "/star2"])
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
self.pm["/*/*"] = "/star/star1"
|
2015-06-25 12:02:52 +00:00
|
|
|
self.assertEqual(list(self.pm._patterns.keys()), ["*"])
|
|
|
|
self.assertEqual(list(self.pm._patterns["*"]._final_patterns.keys()), ["*"])
|
2012-11-26 07:32:01 +00:00
|
|
|
self.assertEqual(self.pm._patterns["*"]._final_patterns["*"]._values, ["/star/star1"])
|
|
|
|
self.assertEqual(sorted(self.pm["/lib/asd"]), ["/star/star1"])
|
|
|
|
|
|
|
|
self.pm["/*"] = "/star2"
|
|
|
|
self.assertEqual(sorted(self.pm["/lib"]), ["/star2"])
|
|
|
|
|
|
|
|
self.assertEqual(sorted(self.pm["/lib/foo"]), ["/star/star1", "/star2"])
|