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

[BUG] transitstacks.io.example_dir() loops over non-existent dir #5

Open
1 task done
thekaveman opened this issue Jun 23, 2021 · 1 comment
Open
1 task done
Labels
bug Something isn't working

Comments

@thekaveman
Copy link
Member

thekaveman commented Jun 23, 2021

Describe the bug

When calling this method with a non-existent directory name, the code attempts to loop over that directory to build a list of available examples. It should instead loop over the root of the examples directory.

To Reproduce

See the Run output from the Python package GitHub Action

Failing tests

Triggering line of code

transitstacks/io.py:139:

def example_dir(example_name: str):
    """Takes an example name and returns the directory.

    Args:
        example_name: name of example
    """
    
    package_dir = os.path.dirname(os.path.abspath(__file__))
    main_example_dir = os.path.join(os.path.dirname(package_dir), "examples")

    example_dir = os.path.join(main_example_dir, example_name)
    
    if not os.path.exists(example_dir):
        available_examples = [
            name for name in os.listdir(example_dir) if os.path.isdir(name)  #<---- error here
        ]

Thoughts on resolution

def example_dir(example_name: str):
    """Takes an example name and returns the directory.

    Args:
        example_name: name of example
    """
    
    package_dir = os.path.dirname(os.path.abspath(__file__))
    main_example_dir = os.path.join(os.path.dirname(package_dir), "examples")

    example_dir = os.path.join(main_example_dir, example_name)
    
    if not os.path.exists(example_dir):
        available_examples = [
            name for name in os.listdir(main_example_dir) if os.path.isdir(name)  #<---- os.listdir(main_example_dir)
        ]

Full stack trace

@thekaveman thekaveman added the bug Something isn't working label Jun 23, 2021
@thekaveman
Copy link
Member Author

Below is output from the failing test run:

===================================== FAILURES ===========================================
____________________________________ test_csv_io _________________________________________
    def test_csv_io():
>       EXAMPLE_DIR = ts.example_dir("prototype")

tests/test_basic.py:26:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
example_name = 'prototype'

    def example_dir(example_name: str):
        """Takes an example name and returns the directory.

        Args:
            example_name: name of example
        """
        package_dir = os.path.dirname(os.path.abspath(__file__))
        main_example_dir = os.path.join(os.path.dirname(package_dir), "examples")

        example_dir = os.path.join(main_example_dir, example_name)

        if not os.path.exists(example_dir):
            available_examples = [
                name for name in os.listdir(main_example_dir) if os.path.isdir(name)
            ]
            ex_str = "\n - ".join(available_examples)
            msg = f"{example_name} not an available example. \
                Available examples:\n - {ex_str}"
>           raise ValueError(msg)
E           ValueError: prototype not an available example.             Available examples:
E            -

transitstacks/io.py:144: ValueError

It seems that the test expects the examples/prototype folder to exist and contain some information:

def test_csv_io():
    EXAMPLE_DIR = ts.example_dir("prototype")
    stack_dict = ts.read_stack_from_dir(EXAMPLE_DIR)
    missing_sheets = set(expected_sheets) - set(list(stack_dict.keys()))
    if missing_sheets:
        print(f"Missing sheets: {missing_sheets}")
    assert not missing_sheets
    assert all(type(x) == pd.DataFrame for x in stack_dict.values())

@e-lo are we missing content in this repo?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant