def test_url_mapping(self): """Test mapping the load paths to urls works.""" self.env.append_path(self.path('a'), '/a') self.env.append_path(self.path('b'), '/b') self.create_files({'a/foo': 'a', 'b/foo': 'b', 'b/bar': '42'}) assert set(self.mkbundle('*', output='out').urls()) == set( ['/a/foo', '/b/bar', '/b/foo'])
def test_url_mapping(self): """Test mapping the load paths to urls works.""" self.env.append_path(self.path('a'), '/a') self.env.append_path(self.path('b'), '/b') self.create_files({ 'a/foo': 'a', 'b/foo': 'b', 'b/bar': '42'}) assert set(self.mkbundle('*', output='out').urls()) == set([ '/a/foo', '/b/bar', '/b/foo' ])
def test_globbing(self): """When used with globbing.""" self.env.append_path(self.path('a')) self.env.append_path(self.path('b')) self.create_files({ 'a/foo': 'a', 'b/foo': 'b', 'b/bar': '42'}) # Returns all files, even duplicate relative filenames in # multiple load paths (foo in this case). bundle = self.mkbundle('*', output='out') assert set(get_all_bundle_files(bundle)) == set([ self.path('a/foo'), self.path('b/foo'), self.path('b/bar') ])
def test_globbing(self): """When used with globbing.""" self.env.append_path(self.path('a')) self.env.append_path(self.path('b')) self.create_files({'a/foo': 'a', 'b/foo': 'b', 'b/bar': '42'}) # Returns all files, even duplicate relative filenames in # multiple load paths (foo in this case). bundle = self.mkbundle('*', output='out') assert set(get_all_bundle_files(bundle)) == set( [self.path('a/foo'), self.path('b/foo'), self.path('b/bar')])
def test_globbed_load_path(self): """The load path itself can contain globs.""" self.env.append_path(self.path('*')) self.create_files({'a/foo': 'a', 'b/foo': 'b', 'dir/bar': 'dir'}) # With a non-globbed reference bundle = self.mkbundle('foo', output='out') assert set(get_all_bundle_files(bundle)) == set([ self.path('a/foo'), self.path('b/foo') ]) # With a globbed reference bundle = self.mkbundle('???', output='out') assert set(get_all_bundle_files(bundle)) == set([ self.path('a/foo'), self.path('b/foo'), self.path('dir/bar') ])
def test_globbed_load_path(self): """The load path itself can contain globs.""" self.env.append_path(self.path('*')) self.create_files({'a/foo': 'a', 'b/foo': 'b', 'dir/bar': 'dir'}) # With a non-globbed reference bundle = self.mkbundle('foo', output='out') assert set(get_all_bundle_files(bundle)) == set( [self.path('a/foo'), self.path('b/foo')]) # With a globbed reference bundle = self.mkbundle('???', output='out') assert set(get_all_bundle_files(bundle)) == set( [self.path('a/foo'), self.path('b/foo'), self.path('dir/bar')])
def check_for_changes(self, mtimes): # Do not update original mtimes dict right away, so that we detect # all bundle changes if a file is in multiple bundles. _new_mtimes = mtimes.copy() changed_bundles = set() # TODO: An optimization was lost here, skipping a bundle once # a single file has been found to have changed. Bring back. for filename, bundles_to_update in self.yield_files_to_watch(): stat = os.stat(filename) mtime = stat.st_mtime if sys.platform == "win32": mtime -= stat.st_ctime if mtimes.get(filename, mtime) != mtime: if callable(bundles_to_update): # Hook for when file has changed try: bundles_to_update = bundles_to_update() except EnvironmentError: # EnvironmentError is what the hooks is allowed to # raise for a temporary problem, like an invalid config import traceback traceback.print_exc() # Don't update anything, wait for another change bundles_to_update = set() if bundles_to_update is True: # Indicates all bundles should be rebuilt for the change bundles_to_update = set(self.environment) changed_bundles |= bundles_to_update _new_mtimes[filename] = mtime _new_mtimes[filename] = mtime mtimes.update(_new_mtimes) return changed_bundles
def yield_files_to_watch(self): for bundle in self.environment: for filename in get_all_bundle_files(bundle): yield filename, set([bundle])