Source

scons / src / scons / Node / FSTests.py

__revision__ = "Node/FSTests.py __REVISION__ __DATE__ __DEVELOPER__"

import os
import sys
import unittest

from scons.Node.FS import init, lookup, Dir, File



built_it = None

class Builder:
    def execute(self, target = None, source = None):
	global built_it
	built_it = 1



class FSTestCase(unittest.TestCase):
    def runTest(self):
	"""This test case handles all of the file system node
	tests in one environment, so we don't have to set up a
	complicated directory structure for each test individually.
	"""
	from TestCmd import TestCmd

	test = TestCmd(workdir = '')
	test.subdir('sub', ['sub', 'dir'])

	wp = test.workpath('')
	sub = test.workpath('sub', '')
	sub_dir = test.workpath('sub', 'dir', '')
	sub_dir_foo = test.workpath('sub', 'dir', 'foo', '')
	sub_dir_foo_bar = test.workpath('sub', 'dir', 'foo', 'bar', '')
	sub_foo = test.workpath('sub', 'foo', '')

	os.chdir(sub_dir)

	init()

	def Dir_test(lpath, path, abspath, up_path):
	    dir = lookup(Dir, lpath)
    	    assert(dir.path == path)
	    assert(dir.abspath == abspath)
	    assert(dir.up().path == up_path)

	Dir_test('foo',		'foo/',		sub_dir_foo,		'.')
	Dir_test('foo/bar',	'foo/bar/',	sub_dir_foo_bar,	'foo/')
	Dir_test('/foo',	'/foo/',	'/foo/',		'/')
	Dir_test('/foo/bar',	'/foo/bar/',	'/foo/bar/',		'/foo/')
	Dir_test('..',		sub,		sub,			wp)
	Dir_test('foo/..',	'.',		sub_dir,		sub)
	Dir_test('../foo',	sub_foo,	sub_foo,		sub)
	Dir_test('.',		'.',		sub_dir,		sub)
	Dir_test('./.',		'.',		sub_dir,		sub)
	Dir_test('foo/./bar',	'foo/bar/',	sub_dir_foo_bar,	'foo/')

	d1 = lookup(Dir, 'd1')

	f1 = lookup(File, 'f1', directory = d1)

	assert(f1.path == 'd1/f1')

	try:
	    f2 = lookup(File, 'f1/f2', directory = d1)
	except TypeError, x:
	    node = x.args[0]
	    assert(node.path == 'd1/f1')
	    assert(node.__class__.__name__ == 'File')
	except:
	    raise

	try:
	    dir = lookup(Dir, 'd1/f1')
	except TypeError, x:
	    node = x.args[0]
	    assert(node.path == 'd1/f1')
	    assert(node.__class__.__name__ == 'File')
	except:
	    raise

	# Test for sub-classing of node building.
	global built_it

	built_it = None
	assert not built_it
	d1.path = "d"		# XXX FAKE SUBCLASS ATTRIBUTE
	d1.sources = "d"	# XXX FAKE SUBCLASS ATTRIBUTE
	d1.builder_set(Builder())
	d1.build()
	assert built_it

	built_it = None
	assert not built_it
	f1.path = "f"		# XXX FAKE SUBCLASS ATTRIBUTE
	f1.sources = "f"	# XXX FAKE SUBCLASS ATTRIBUTE
	f1.builder_set(Builder())
	f1.build()
	assert built_it


if __name__ == "__main__":
    suite = unittest.TestSuite()
    suite.addTest(FSTestCase())
    if not unittest.TextTestRunner().run(suite).wasSuccessful():
	sys.exit(1)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.