def test_shell_discovery_plugin_scan_exceptions(): """Test that the shell discovery plugin properly respects exceptions.""" shdp = ShellDiscoveryPlugin() if not shdp.file_command_exists(): pytest.skip( "File command does not exist. Skipping test that requires it.") package = Package("valid_package", os.path.join(os.path.dirname(__file__), "valid_package")) exceptions = Exceptions( os.path.join(os.path.dirname(__file__), "exceptions.yaml")) shdp.scan(package, "level", exceptions) expected_src = [ "test.sh", "oddextensionsh.source", "oddextensionbash.source", "oddextensionzsh.source", "oddextensioncsh.source", "oddextensionksh.source", "oddextensiondash.source", ] # We have to add the path to each of the above...yuck expected_src_fullpath = [ os.path.join(package.path, filename) for filename in expected_src ] # Neat trick to verify that two unordered lists are the same assert set(package["shell_src"]) == set(expected_src_fullpath)
def test_shell_discovery_plugin_scan_invalid(): """Test that the discovery plugin doesn't find non-shell files.""" shdp = ShellDiscoveryPlugin() package = Package( "invalid_package", os.path.join(os.path.dirname(__file__), "invalid_package")) shdp.scan(package, "level") assert not package["shell_src"]
def test_shell_discovery_plugin_scan_invalid(): """Test that the discovery plugin doesn't find non-shell files.""" shdp = ShellDiscoveryPlugin() if not shdp.file_command_exists(): pytest.skip( "File command does not exist. Skipping test that requires it.") package = Package( "invalid_package", os.path.join(os.path.dirname(__file__), "invalid_package")) shdp.scan(package, "level") assert not package["shell_src"]
def test_shell_discovery_plugin_no_file_cmd(): """ Test when file command does not exist. Test that files are not discovered with file command output if file command does not exist. """ with modified_environ(PATH=""): shdp = ShellDiscoveryPlugin() package = Package( "valid_package", os.path.join(os.path.dirname(__file__), "valid_package")) shdp.scan(package, "level") expected = ["test.sh", os.path.join("ignore_this", "ignoreme.bash")] # We have to add the path to each of the above...yuck expected_fullpath = [ os.path.join(package.path, filename) for filename in expected ] # Neat trick to verify that two unordered lists are the same assert set(package["shell_src"]) == set(expected_fullpath)
def test_shell_discovery_plugin_scan_valid(): """Test that the Shell discovery plugin finds valid shell files.""" shdp = ShellDiscoveryPlugin() package = Package("valid_package", os.path.join(os.path.dirname(__file__), "valid_package")) shdp.scan(package, "level") expected = ["test.sh", os.path.join("ignore_this", "ignoreme.bash")] if shdp.file_command_exists(): expected += [ "oddextensionsh.source", "oddextensionbash.source", "oddextensionzsh.source", "oddextensioncsh.source", "oddextensionksh.source", "oddextensiondash.source", ] # We have to add the path to each of the above...yuck expected_fullpath = [ os.path.join(package.path, filename) for filename in expected ] # Neat trick to verify that two unordered lists are the same assert set(package["shell_src"]) == set(expected_fullpath)