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

Nested params #15

Closed
birnbera opened this issue Sep 22, 2022 · 6 comments · Fixed by #50
Closed

Nested params #15

birnbera opened this issue Sep 22, 2022 · 6 comments · Fixed by #50

Comments

@birnbera
Copy link

Thank you for creating this package! I love the simplicity and flexibility. Unfortunately, I have run into an issue that will make it difficult to use nf-test in practice. Most Nextflow pipelines have some degree of nesting in their params, e.g.:

{
    "outer": {
        "inner": "value"
    }
}

When running a test that includes nested params, I get an error. As an example:

nextflow_process {

    name "Test Process copy"
    script "main.nf"
    process "copy"

    test("Should run without failures") {

        when {
            params {
                output_dir = "tests/results"
                outer {
                    inner = 'value'
                }
            }
            process {
                """
                input[0] = file("test-file.txt")
                """
            }
        }

        then {
            assert process.success
            with(process.out.newfile) {
                assert size() == 1
                with(file(get(0))) {
                    assert name == 'someotherfilename.txt'
                    assert text == file('test-file.txt').text + 'extra\n'
                }
            }
        }
    }
}

Running this, I get:

groovy.lang.MissingMethodException: No signature of method: main_copy_nf$_run_closure1$_closure2.outer() is applicable for argument types: (main_copy_nf$_run_closure1$_closure2$_closure3$_closure5$_closure7) values: [main_copy_nf$_run_closure1$_closure2$_closure3$_closure5$_closure7@6093d508]
  Possible solutions: use([Ljava.lang.Object;), use([Ljava.lang.Object;), grep(), every(), dump(), grep()

Am I specifying the params incorrectly or are they not yet fully supported within nf-test? Also, is it possible to pass params as a file (i.e. JSON or YAML) rather than as code?

@birnbera
Copy link
Author

I just realized that it does work to define params using standard groovy for nested objects, as in:

when {
    params {
        output_dir = "tests/results"
        outer = [inner: 'value']
    }
...

It's not a bad workaround, but it would be nice to have a unified syntax between Nextflow and nf-test. I'd also still be interested in passing params as a file if that were possible.

@lukfor
Copy link
Collaborator

lukfor commented Sep 23, 2022

Thanks for reporting this issues and giving nf-test a try. It definitely makes sense to use the same syntax as Nextflow. 👍 We will try to fix it.

Passing params as a file is not yet supported, but we will think about it...

@Khushbu04in
Copy link

Thanks for reporting this issues and giving nf-test a try. It definitely makes sense to use the same syntax as Nextflow. 👍 We will try to fix it.

Passing params as a file is not yet supported, but we will think about it...

We tried doing that and it is working for us:
def other_param_yaml = new FileInputStream(new File("file name"))
new Yaml().load(other_param_yaml).each { k, v -> delegate[k] = v }

@lukfor
Copy link
Collaborator

lukfor commented Oct 11, 2022

Thank you @Khushbu04in! I will reuse your code to create a load function:

when {
    params {
        load("file name")
    }

Best, lukas.

@odoublewen
Copy link

Passing params from a file (json, yaml, etc) is almost a must have feature, IMO. We have big datasets we'd like to test and it would (will) be very painful to convert the json to the groovy object notation. I'm not sure of anyway to do it other than by hand.

@Khushbu04in could you share your full approach? I'm not sure how to get the data into the when {} closure.

I can do this outside of nextflow_pipeline{}:

slurper = new groovy.json.JsonSlurper()                                                                                                                                                      
params_file = new File('tests/data/params/params.json')                                                                                                                           
params_data = slurper.parseText(params_file.text)

... and it works in the sense that params_data holds the params in groovy dotted notation.

But if I then do this:

    test("Should run without failures") {

        when {
            params = params_data
        }

I get this:

groovy.lang.MissingPropertyException: No such property: params_data for class: com.askimed.nf.test.lang.TestContext

@lukfor
Copy link
Collaborator

lukfor commented Nov 7, 2022

This feature is now available in version 0.7.1

👉 https://code.askimed.com/nf-test/testcases/global_variables/

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

Successfully merging a pull request may close this issue.

4 participants