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

[CT-3495] I want to use spacing to make my csv input/expected output mock data more readable for unit tests #9280

Open
2 tasks done
Tracked by #8283
graciegoheen opened this issue Dec 13, 2023 · 3 comments
Labels
enhancement New feature or request paper_cut A small change that impacts lots of users in their day-to-day unit tests Issues related to built-in dbt unit testing functionality

Comments

@graciegoheen
Copy link
Contributor

graciegoheen commented Dec 13, 2023

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

If I want to use format:csv for defining my mock data for a unit test definition, I cannot use any spaces:

unit_tests:
  - name: b
    model: dim_wizards 
    given: 
      - input: ref('stg_wizards')
        format: csv
        rows: |
          wizard_id,email,email_top_level_domain
          1,cool@example.com,example.com
          2,cool@unknown.com,unknown.com
          3,badgmail.com,gmail.com
          4,missingdot@gmailcom,gmail.com
...

This is even true if I want to use a fixture file:

unit_tests:
  - name: c
    model: dim_wizards 
    given: 
      - input: ref('stg_wizards')
        format: csv
        fixture: wizard_emails_input
...
# tests/fixtures/wizard_emails_input

wizard_id,email,email_top_level_domain
1,cool@example.com,example.com
2,cool@unknown.com,unknown.com
3,badgmail.com,gmail.com
4,missingdot@gmailcom,gmail.com

This makes the text harder to read / write.

Expected Behavior

I should be able to use spaces when defining my mock data for a unit test using format: csv:

unit_tests:
  - name: b
    model: dim_wizards 
    given: 
      - input: ref('stg_wizards')
        format: csv
        rows: |
          wizard_id, email, email_top_level_domain
          1, cool@example.com, example.com
          2, cool@unknown.com, unknown.com
          3, badgmail.com, gmail.com
          4, missingdot@gmailcom, gmail.com
...

Spaces should also be allowed in fixture files:

unit_tests:
  - name: c
    model: dim_wizards 
    given: 
      - input: ref('stg_wizards')
        format: csv
        fixture: wizard_emails_input
...
# tests/fixtures/wizard_emails_input

wizard_id, email, email_top_level_domain
1, cool@example.com, example.com
2, cool@unknown.com, unknown.com
3, badgmail.com, gmail.com
4, missingdot@gmailcom, gmail.com
@graciegoheen graciegoheen added the enhancement New feature or request label Dec 13, 2023
@github-actions github-actions bot changed the title I want to use spacing to make my csv input/expected output mock data more readable for unit tests [CT-3495] I want to use spacing to make my csv input/expected output mock data more readable for unit tests Dec 13, 2023
@graciegoheen
Copy link
Contributor Author

Notes from refinement:

  • is this actually supported for csvs / seeds

@graciegoheen
Copy link
Contributor Author

graciegoheen commented Jan 2, 2024

Here's what happens with seeds:

  1. created a new seed in my project with spaces
column_a, column_b
1, grace
2, doug
  1. executed dbt seed
    Image

The created table in the warehouse -> my_seed

So the fields for column_b included the spaces: grace & doug. This does seem to be consistent with what's happening for unit tests - see example here.

@graciegoheen graciegoheen added this to the v1.9 milestone Apr 11, 2024
@graciegoheen graciegoheen added the unit tests Issues related to built-in dbt unit testing functionality label Aug 31, 2024
@graciegoheen graciegoheen removed this from the v1.9 milestone Aug 31, 2024
@graciegoheen graciegoheen added the paper_cut A small change that impacts lots of users in their day-to-day label Aug 31, 2024
@gnilrets
Copy link

I'd like this too (and the ability to use | as a delimiter).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request paper_cut A small change that impacts lots of users in their day-to-day unit tests Issues related to built-in dbt unit testing functionality
Projects
None yet
Development

No branches or pull requests

2 participants