def test_find_all_javascript_resources_in_the_paths(self): paths_to_test_files = [os.path.join(self.test_env_dir, 'test.js'), os.path.join(self.test_env_dir, 'test.css'), os.path.join(self.test_env_dir, 'test.html')] helpers.create_files(paths_to_test_files) resources = Resource.find_all_of_type_in_paths('javascript', Paths(self.test_env_dir, include_cwd=False)) helpers.clean_up_files(paths_to_test_files) self.assertEquals(1, len(resources), 'One and only one javascript file should be found')
def test_run_with_single_resource(self): paths_to_processable_test_files = [ os.path.join(self.test_env_dir, 'dir1', 'file1.js')] create_files(paths_to_processable_test_files) app = Application(file_list=[paths_to_processable_test_files[0]]) self.assertEqual(0, app.run()) clean_up_files(paths_to_processable_test_files)
def test_search_for_javascript_resources_in_paths_without_any_search_paths_returns_none( self): test_env = Paths(self.test_env_dir, include_cwd=False) path_to_test_file = os.path.join(self.test_env_dir, 'test.css') helpers.create_files(path_to_test_file) resources = Resource.find_all_of_type_in_paths('javascript', test_env) self.assertEquals(None, resources)
def test_run_with_single_resource(self): paths_to_processable_test_files = [ os.path.join(self.test_env_dir, 'dir1', 'file1.js') ] create_files(paths_to_processable_test_files) app = Application(file_list=[paths_to_processable_test_files[0]]) self.assertEqual(0, app.run()) clean_up_files(paths_to_processable_test_files)
def test_exists_property(self): path_to_test_file = os.path.join(self.test_env_dir, 'test.js') helpers.clean_up_files(path_to_test_file) resource = Resource(path_to_test_file) # file does not exist yet self.assertFalse(resource.exists) helpers.create_files(path_to_test_file) self.assertTrue(resource.exists) helpers.clean_up_files(path_to_test_file)
def test_run_with_single_resource_with_requirement(self): paths_to_test_files = [ os.path.join(self.test_env_dir, 'dir1', 'file1.js'), os.path.join(self.test_env_dir, 'dir2', 'file2.js')] clean_up_files(paths_to_test_files) create_files(paths_to_test_files) create_file_with_content(paths_to_test_files[0], '// This is file 1\n//= require file2') create_file_with_content(paths_to_test_files[1], '// This is file 2') app = Application(path_list=[self.test_env_dir], file_list=[paths_to_test_files[0]]) self.assertEqual(0, app.run()) clean_up_files(paths_to_test_files)
def test_find_all_javascript_resources_in_the_paths(self): paths_to_test_files = [ os.path.join(self.test_env_dir, 'test.js'), os.path.join(self.test_env_dir, 'test.css'), os.path.join(self.test_env_dir, 'test.html') ] helpers.create_files(paths_to_test_files) resources = Resource.find_all_of_type_in_paths( 'javascript', Paths(self.test_env_dir, include_cwd=False)) helpers.clean_up_files(paths_to_test_files) self.assertEquals(1, len(resources), 'One and only one javascript file should be found')
def test_run_with_single_resource_with_requirement(self): paths_to_test_files = [ os.path.join(self.test_env_dir, 'dir1', 'file1.js'), os.path.join(self.test_env_dir, 'dir2', 'file2.js') ] clean_up_files(paths_to_test_files) create_files(paths_to_test_files) create_file_with_content(paths_to_test_files[0], '// This is file 1\n//= require file2') create_file_with_content(paths_to_test_files[1], '// This is file 2') app = Application(path_list=[self.test_env_dir], file_list=[paths_to_test_files[0]]) self.assertEqual(0, app.run()) clean_up_files(paths_to_test_files)
def test_detects_minification_from_file_name(self): test_file_paths = [ os.path.join(self.test_env_dir, 'dir1', 'file1.js'), os.path.join(self.test_env_dir, 'dir2', 'file1.min.js'), os.path.join(self.test_env_dir, 'dir2', 'file1-min.js')] helpers.create_files(test_file_paths) unminified_resource = Resource(test_file_paths[0]) minified_resource_with_dot = Resource(test_file_paths[1]) minified_resource_with_dash = Resource(test_file_paths[2]) self.assertFalse(unminified_resource.minified) self.assertTrue(minified_resource_with_dot.minified) self.assertTrue(minified_resource_with_dash.minified)
def test_detects_minification_from_file_name(self): test_file_paths = [ os.path.join(self.test_env_dir, 'dir1', 'file1.js'), os.path.join(self.test_env_dir, 'dir2', 'file1.min.js'), os.path.join(self.test_env_dir, 'dir2', 'file1-min.js') ] helpers.create_files(test_file_paths) unminified_resource = Resource(test_file_paths[0]) minified_resource_with_dot = Resource(test_file_paths[1]) minified_resource_with_dash = Resource(test_file_paths[2]) self.assertFalse(unminified_resource.minified) self.assertTrue(minified_resource_with_dot.minified) self.assertTrue(minified_resource_with_dash.minified)
def test_find_all_in_paths(self): paths_to_processable_test_files = [ os.path.join(self.test_env_dir, 'dir1', 'file1.js'), os.path.join(self.test_env_dir, 'dir2', 'file2.css')] paths_to_unprocessable_test_files = [ os.path.join(self.test_env_dir, 'dir1', 'movie.avi'), os.path.join(self.test_env_dir, 'some.other.thing')] helpers.create_files(paths_to_processable_test_files) helpers.create_files(paths_to_unprocessable_test_files) resources = Resource.find_all_in_paths(Paths(self.test_env_dir, include_cwd=False)) self.assertEquals(2, len(resources)) self.assertEqual(paths_to_processable_test_files[0], resources[0].path_to_file) self.assertEqual(paths_to_processable_test_files[1], resources[1].path_to_file)
def test_find_all_in_paths(self): paths_to_processable_test_files = [ os.path.join(self.test_env_dir, 'dir1', 'file1.js'), os.path.join(self.test_env_dir, 'dir2', 'file2.css') ] paths_to_unprocessable_test_files = [ os.path.join(self.test_env_dir, 'dir1', 'movie.avi'), os.path.join(self.test_env_dir, 'some.other.thing') ] helpers.create_files(paths_to_processable_test_files) helpers.create_files(paths_to_unprocessable_test_files) resources = Resource.find_all_in_paths( Paths(self.test_env_dir, include_cwd=False)) self.assertEquals(2, len(resources)) self.assertEqual(paths_to_processable_test_files[0], resources[0].path_to_file) self.assertEqual(paths_to_processable_test_files[1], resources[1].path_to_file)
def test_search_for_javascript_resources_in_paths_without_any_search_paths_returns_none(self): test_env = Paths(self.test_env_dir, include_cwd=False) path_to_test_file = os.path.join(self.test_env_dir, 'test.css') helpers.create_files(path_to_test_file) resources = Resource.find_all_of_type_in_paths('javascript', test_env) self.assertEquals(None, resources)