Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for channels as function output is problematic #235

Open
mahesh-panchal opened this issue Jul 17, 2024 · 1 comment
Open

Support for channels as function output is problematic #235

mahesh-panchal opened this issue Jul 17, 2024 · 1 comment

Comments

@mahesh-panchal
Copy link

mahesh-panchal commented Jul 17, 2024

Support for channels as function output is not fully functional.

main.nf:

def defaultChannel(){
    Channel.value(1)
}

with main.nf.test:

nextflow_function {

    name "Test Functions"
    script "main.nf"

	

    test("Test Function defaultChannel") {

        function "defaultChannel"

        when {
            function {
                """
                // define inputs of the function here. Example:
                // input[0] = 1
                """
            }
        }

        then {
            println function.properties
            assert function.success
            assert snapshot(function.result).match()
        }

    }

	

}

results in:

$ nf-test test tests/main.nf.test 
Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -XX:ActiveProcessorCount=1

🚀 nf-test 0.8.4
https://code.askimed.com/nf-test
(c) 2021 - 2024 Lukas Forer and Sebastian Schoenherr


Test Functions

  Test [a7c7feae] 'Test Function defaultChannel' [stderr:[], class:class com.askimed.nf.test.lang.function.Function, errorReport:, exitStatus:1, mapping:
                // define inputs of the function here. Example:
                // input[0] = 1
                , failed:true, result:null, stdout:[ERROR ~ Cannot invoke "groovyx.gpars.serial.SerialContext.add(groovyx.gpars.serial.SerialHandle)" because "this.context" is null, ,  -- Check script 'meta/mock.nf' at line: 35 or see '/workspace/Nextflow_sandbox/.nf-test/tests/a7c7feae6c08f02d7cd531ca2156d60a/meta/nextflow.log' file for more details], errorMessage:, trace:com.askimed.nf.test.lang.WorkflowTrace@304b9f1a, name:null, success:false]
FAILED (8.337s)

  Assertion failed: 
  
  assert function.success
         |        |
         |        false
         com.askimed.nf.test.lang.function.Function@1059754c (toString() == null)
  
  Nextflow stdout:
  
  ERROR ~ Cannot invoke "groovyx.gpars.serial.SerialContext.add(groovyx.gpars.serial.SerialHandle)" because "this.context" is null
  
   -- Check script 'meta/mock.nf' at line: 35 or see '/workspace/Nextflow_sandbox/.nf-test/tests/a7c7feae6c08f02d7cd531ca2156d60a/meta/nextflow.log' file for more details
  Nextflow stderr:
  
  



FAILURE: Executed 1 tests in 8.346s (1 failed)

When using files in a channel as output, the test passes but the output is an empty map:
main.nf:

def defaultChannel(){
    Channel.fromPath("$projectDir/tests/nextflow.config")
}

main.nf.test:

nextflow_function {

    name "Test Functions"
    script "main.nf"

	

    test("Test Function defaultChannel") {

        function "defaultChannel"

        when {
            function {
                """
                // define inputs of the function here. Example:
                // input[0] = 1
                """
            }
        }

        then {
            println function.properties
            assert function.success
            assert snapshot(function.result).match()
        }

    }

	

}

terminal:

$ nf-test test tests/main.nf.test 
Picked up JAVA_TOOL_OPTIONS: -XX:+UseContainerSupport -XX:ActiveProcessorCount=1

🚀 nf-test 0.8.4
https://code.askimed.com/nf-test
(c) 2021 - 2024 Lukas Forer and Sebastian Schoenherr


Test Functions

  Test [a7c7feae] 'Test Function defaultChannel' [stderr:[], class:class com.askimed.nf.test.lang.function.Function, errorReport:null, exitStatus:0, mapping:
                // define inputs of the function here. Example:
                // input[0] = 1
                , failed:false, result:[:], stdout:[], errorMessage:null, trace:com.askimed.nf.test.lang.WorkflowTrace@5b56b654, name:null, success:true]
PASSED (14.31s)
  Snapshots:
    1 created [Test Function defaultChannel]


Snapshot Summary:
  1 created

SUCCESS: Executed 1 tests in 14.321s

main.nf.test.snap:

{
    "Test Function defaultChannel": {
        "content": [
            {
                
            }
        ],
        "meta": {
            "nf-test": "0.8.4",
            "nextflow": "24.04.3"
        },
        "timestamp": "2024-07-17T14:16:19.672087809"
    }
}

Additional context.

I use functions to wrap common channel manipulations to help with code readability.

@antunderwood
Copy link

Adding my +1 to this since we likewise use functions to make the main.ng more readable by wrapping complex channel manipulations.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants