def test_dispatch_when_filesystem_has_been_modified(): # Create an empty www_root www = FilesystemTree() # Help the dispatchers that rely on `mtime` st = os.stat(www.root) os.utime(www.root, (st.st_atime - 10, st.st_mtime - 10)) # Initialize the dispatchers dispatchers = [] for dispatcher_class in DISPATCHER_CLASSES: dispatchers.append(dispatcher_class( www_root = www.root, is_dynamic = lambda n: n.endswith('.spt'), indices = ['index.html'], typecasters = {}, )) dispatchers[-1].build_dispatch_tree() # Now add an index file and try to dispatch www.mk(('index.html', 'Greetings, program!')) for dispatcher in dispatchers: print("Attempting dispatch with", dispatcher.__class__.__name__) result = dispatcher.dispatch('/', ['']) if dispatcher.__class__.__name__ == 'UserlandDispatcher': assert result.status == DispatchStatus.unindexed assert result.match == www.root + os.path.sep else: assert result.status == DispatchStatus.okay assert result.match == www.resolve('index.html') assert result.wildcards is None assert result.extension is None assert result.canonical is None
def test_sd_false_via_constructor(): try: fs = FilesystemTree(should_dedent=False) fs.mk(('some/dir/file.txt', ' Greetings, program!')) contents = open(fs.resolve('some/dir/file.txt')).read() assert contents == ' Greetings, program!' finally: fs.remove()
def test_encoding_cp1140_via_constructor(): try: fs = FilesystemTree(encoding='cp1140') fs.mk(('file.txt', A_UNICODE)) contents = open(fs.resolve('file.txt'), 'rb').read() assert contents == AS_CP1140 finally: fs.remove()
def test_encoding_cp1140_via_constructor(): try: fs = FilesystemTree(encoding='cp1140') fs.mk(('file.txt', A_UNICODE)) contents = open(fs.resolve('file.txt'), 'rb').read() assert contents == AS_CP1140 finally: fs.remove()
def test_sd_false_via_constructor(): try: fs = FilesystemTree(should_dedent=False) fs.mk(('some/dir/file.txt', ' Greetings, program!')) contents = open(fs.resolve('some/dir/file.txt')).read() assert contents == ' Greetings, program!' finally: fs.remove()
def test_encoding_utf8_via_instance_attribute(): try: fs = FilesystemTree(encoding='cp1140') fs.encoding = 'utf8' fs.mk(('file.txt', A_UNICODE)) contents = open(fs.resolve('file.txt'), 'rb').read() assert contents == AS_UTF8 finally: fs.remove()
def test_sd_true_via_instance_attribute(): try: fs = FilesystemTree(should_dedent=False) fs.should_dedent = True fs.mk(('some/dir/file.txt', ' Greetings, program!')) contents = open(fs.resolve('some/dir/file.txt')).read() assert contents == 'Greetings, program!' finally: fs.remove()
def test_sd_true_via_instance_attribute(): try: fs = FilesystemTree(should_dedent=False) fs.should_dedent = True fs.mk(('some/dir/file.txt', ' Greetings, program!')) contents = open(fs.resolve('some/dir/file.txt')).read() assert contents == 'Greetings, program!' finally: fs.remove()
def test_encoding_utf8_via_instance_attribute(): try: fs = FilesystemTree(encoding='cp1140') fs.encoding = 'utf8' fs.mk(('file.txt', A_UNICODE)) contents = open(fs.resolve('file.txt'), 'rb').read() assert contents == AS_UTF8 finally: fs.remove()
def test_encoding_utf8_via_constructor(): _reset = FilesystemTree.encoding try: FilesystemTree.encoding = 'cp1140' fs = FilesystemTree(encoding='utf8') fs.mk(('file.txt', A_UNICODE)) contents = open(fs.resolve('file.txt'), 'rb').read() assert contents == AS_UTF8 finally: FilesystemTree.encoding = _reset fs.remove()
def test_encoding_cp1140_via_class_attribute(): _reset = FilesystemTree.encoding try: FilesystemTree.encoding = 'cp1140' fs = FilesystemTree() fs.mk(('file.txt', A_UNICODE)) contents = open(fs.resolve('file.txt'), 'rb').read() assert contents == AS_CP1140 finally: FilesystemTree.encoding = _reset fs.remove()
def test_encoding_utf8_via_constructor(): _reset = FilesystemTree.encoding try: FilesystemTree.encoding = 'cp1140' fs = FilesystemTree(encoding='utf8') fs.mk(('file.txt', A_UNICODE)) contents = open(fs.resolve('file.txt'), 'rb').read() assert contents == AS_UTF8 finally: FilesystemTree.encoding = _reset fs.remove()
def test_encoding_cp1140_via_class_attribute(): _reset = FilesystemTree.encoding try: FilesystemTree.encoding = 'cp1140' fs = FilesystemTree() fs.mk(('file.txt', A_UNICODE)) contents = open(fs.resolve('file.txt'), 'rb').read() assert contents == AS_CP1140 finally: FilesystemTree.encoding = _reset fs.remove()
def test_sd_false_via_class_attribute(): _reset = FilesystemTree.should_dedent try: FilesystemTree.should_dedent = False fs = FilesystemTree() fs.mk(('some/dir/file.txt', ' Greetings, program!')) contents = open(fs.resolve('some/dir/file.txt')).read() assert contents == ' Greetings, program!' finally: FilesystemTree.should_dedent = _reset fs.remove()
def test_sd_false_via_class_attribute(): _reset = FilesystemTree.should_dedent try: FilesystemTree.should_dedent = False fs = FilesystemTree() fs.mk(('some/dir/file.txt', ' Greetings, program!')) contents = open(fs.resolve('some/dir/file.txt')).read() assert contents == ' Greetings, program!' finally: FilesystemTree.should_dedent = _reset fs.remove()
def test_dispatcher_returns_a_result(dispatcher_class): www = FilesystemTree() www.mk(('index.html', 'Greetings, program!'),) dispatcher = dispatcher_class( www_root = www.root, is_dynamic = lambda n: n.endswith('.spt'), indices = ['index.html'], typecasters = {}, ) dispatcher.build_dispatch_tree() result = dispatcher.dispatch('/', ['']) assert result.status == DispatchStatus.okay assert result.match == os.path.join(www.root, 'index.html') assert result.wildcards == None
class RunDeployHooks(DeployHooksHarness): def setUp(self): self.ft = FilesystemTree() self.db.run('DROP TABLE IF EXISTS foo;') def tearDown(self): self.ft.remove() self.db.run('DROP TABLE IF EXISTS foo;') def test_runs_deploy_hooks(self): self.ft.mk(('before.sql', 'CREATE TABLE foo (bar int);'), ('after.py', AFTER_PY), ('after.sql', 'ALTER TABLE foo RENAME COLUMN bar TO baz;')) raises(ProgrammingError, self.db.all, 'SELECT name FROM foo') self.run_deploy_hooks(_deploy_dir=self.ft.root) assert self.db.all('SELECT baz FROM foo ORDER BY baz') == [42, 537]