Skip to content

Commit

Permalink
update mock executable to process args
Browse files Browse the repository at this point in the history
  • Loading branch information
esiegel committed Dec 31, 2023
1 parent dc70318 commit c0b017c
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 6 deletions.
56 changes: 55 additions & 1 deletion tests/testthat/mock_louper
Original file line number Diff line number Diff line change
@@ -1,5 +1,59 @@
#!/usr/bin/env bash

echo "-----------RUNNING MOCK LOUPER EXECUTABLE--------------"
echo Arguments passed to the script: "$@"

# Default values
force=false

# Check if the correct number of arguments is provided
if [ "$#" -lt 3 ] || [ "$#" -gt 4 ]; then
echo "Usage: $0 create --input=SOME_PATH --output=SOME_PATH [--force]"
exit 1
fi

# Check if the first argument is "create"
if [ "$1" != "create" ]; then
echo "Error: First argument must be 'create'"
exit 1
fi

# shift args
shift

# Parse and validate the input and output options
input=""
output=""

while [ "$#" -gt 0 ]; do
case "$1" in
--input=*)
input="${1#*=}"
;;
--output=*)
output="${1#*=}"
;;
--force)
force=true
;;
*)
echo "Error: Unknown option '$1'"
exit 1
;;
esac
shift
done

# Check if input and output paths are provided
if [ -z "$input" ] || [ -z "$output" ]; then
echo "Error: Both --input and --output options must be provided"
exit 1
fi

# Additional processing with the arguments can be added here

echo "Action: create"
echo "Input path: $input"
echo "Output path: $output"
echo "Force: $force"

echo "-------------------------------------------------------"
63 changes: 62 additions & 1 deletion tests/testthat/mock_louper.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,66 @@
@echo off

echo "-----------RUNNING MOCK LOUPER.BAT EXECUTABLE--------------"
echo Arguments passed to the script: %*

setlocal enabledelayedexpansion

set "force=false"

REM Check if the correct number of arguments is provided
if "%~1" neq "create" (
echo Error: First argument must be 'create'
goto :eof
)
shift

REM Parse and validate the input and output options
set "input="
set "output="

:parse_args
if "%~1" equ "" goto :check_paths

if /i "%~1" equ "--input" (
set "input=%~2"
shift
shift
goto :parse_args
)

if /i "%~1" equ "--output" (
set "output=%~2"
shift
shift
goto :parse_args
)

if /i "%~1" equ "--force" (
set "force=true"
shift
goto :parse_args
)

echo Error: Unknown option '%1'
goto :eof

:check_paths
REM Check if input and output paths are provided
if not defined input (
echo Error: --input option must be provided
goto :eof
)

if not defined output (
echo Error: --output option must be provided
goto :eof
)

REM Additional processing with the arguments can be added here

echo Action: create
echo Input path: !input!
echo Output path: !output!
echo Force: !force!

:end
echo "-----------------------------------------------------------"
23 changes: 19 additions & 4 deletions tests/testthat/test-lib.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test_that("can run create_loupe_from_seurat", {
create_default_seurat_obj <- function() {
barcode_count <- 3

count_mat <- create_count_mat(100, barcode_count, valid_barcodes = TRUE)
Expand All @@ -9,23 +9,38 @@ test_that("can run create_loupe_from_seurat", {
obj[["proj1"]] <- proj
obj[["cluster1"]] <- cluster

obj
}

test_that("can run create_loupe_from_seurat", {
# create eula lock file to avoid interactive setup
eula_create()

obj <- create_default_seurat_obj()
x <- create_loupe_from_seurat(obj, executable_path = get_executable_path())
expect(x, "create_loupe_from_seurat returns TRUE")
})

test_that("can run create_loupe with spaces in output_name", {
# create eula lock file to avoid interactive setup
eula_create()

obj <- create_default_seurat_obj()
x <- create_loupe_from_seurat(obj, executable_path = get_executable_path(), output_name = "name with spaces")
expect(x, "create_loupe_from_seurat returns TRUE")
})

test_that("can run create_loupe", {
# create eula lock file to avoid interactive setup
eula_create()

barcode_count <- 5
count_mat <- create_count_mat(100, barcode_count, valid_barcodes = TRUE)
proj <- create_dense_mat(barcode_count, 2)
clusters <- list("f1" = factor(c("a", "c", "b", "a", "b"), levels=c("a", "b", "c"), ordered=TRUE))
projections <- list("p1" = proj)

# create eula lock file to avoid interactive setup
eula_create()

x <- create_loupe(count_mat, clusters = clusters, projections = projections, executable_path = get_executable_path())
expect(x, "create_loupe returns TRUE")
})

0 comments on commit c0b017c

Please sign in to comment.