GreenBuildingRegistry / usaddress-scourgify

Clean US addresses following USPS pub 28 and RESO guidelines
MIT License
206 stars 47 forks source link

a couple of tests fail #10

Closed zyxue closed 4 years ago

zyxue commented 4 years ago

https://files.pythonhosted.org/packages/7c/43/734f8aad7f4d3f5ba02a52696dcead52a6d2d8b66f4fa98523e5b806a662/usaddress-scourgify-0.1.11.tar.gz

========================================================================================================== test session starts ==========================================================================================================
platform darwin -- Python 3.7.6, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
rootdir: /path/to/scourgify/scourgify/usaddress-scourgify-0.1.11
collected 25 items                                                                                                                                                                                                                      

scourgify/tests/test_address_normalization.py ............F...........                                                                                                                                                            [ 96%]
scourgify/tests/test_cleaning.py F                                                                                                                                                                                                [100%]

=============================================================================================================== FAILURES ================================================================================================================
_____________________________________________________________________________________ TestAddressNormalizationUtils.test_handle_abnormal_occupancy ______________________________________________________________________________________

self = <scourgify.tests.test_address_normalization.TestAddressNormalizationUtils testMethod=test_handle_abnormal_occupancy>

    def test_handle_abnormal_occupancy(self):
        addr_str = '123 SW MAIN UN'
        expected = OrderedDict([
            ('AddressNumber', '123'),
            ('StreetNamePreDirectional', 'SW'),
            ('StreetName', 'MAIN'),
            ('StreetNamePostType', 'UN'),
        ])
        result = parse_address_string(addr_str)
        self.assertEqual(expected, result)

        addr_str = '123 SW MAIN UN A'
        expected = OrderedDict([
            ('AddressNumber', '123'),
            ('StreetNamePreDirectional', 'SW'),
            ('StreetName', 'MAIN'),
            ('OccupancyType', 'UN'),
            ('OccupancyIdentifier', 'A')
        ])
        result = parse_address_string(addr_str)
>       self.assertEqual(expected, result)
E       AssertionError: Order[91 chars]), ('OccupancyType', 'UN'), ('OccupancyIdentifier', 'A')]) != Order[91 chars]), ('StreetNamePostType', 'UN'), ('OccupancyIdentifier', 'A')])

scourgify/tests/test_address_normalization.py:650: AssertionError
________________________________________________________________________________________________ CleaningTests.test_strip_occupancy_type ________________________________________________________________________________________________

self = <scourgify.tests.test_cleaning.CleaningTests testMethod=test_strip_occupancy_type>

    def test_strip_occupancy_type(self):
        expected = '33'

        line2 = 'Unit 33'
        result = strip_occupancy_type(line2)
        self.assertEqual(result, expected)

        line2 = 'Apartment 33'
        result = strip_occupancy_type(line2)
        self.assertEqual(result, expected)

        line2 = 'Unit #33'
        result = strip_occupancy_type(line2)
        self.assertEqual(result, expected)

        line2 = 'Building 3 Unit 33'
        result = strip_occupancy_type(line2)
        self.assertEqual(result, expected)

        line2 = 'Building 3 UN 33'
        result = strip_occupancy_type(line2)
>       self.assertEqual(result, expected)
E       AssertionError: '3 UN 33' != '33'
E       - 3 UN 33
E       + 33

scourgify/tests/test_cleaning.py:38: AssertionError
--------------------------------------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------------------------------------
['3', 'UN', '33']
fablet commented 4 years ago

The zip file releases are missing the "scourgify/tests/config/address_constants.yaml" file. I have tried a couple of things, but cannot figure out why the build is excluding that file. If you can help me figure out how to ensure that file is included in the build, I would be happy to roll out a new release which includes that file. Lacking that, you will need to grab the file from the repo and tell your testing environment where the file is, such as is done through tox's setenv

zyxue commented 4 years ago

I just cloned your repo, install the dependencies, and run,

tree scourgify/tests/
scourgify/tests/
├── __init__.py
├── config
│   └── address_constants.yaml
├── test_address_normalization.py
└── test_cleaning.py
pytest scourgify/tests/

it still produces the same error, are you sure it's due to missing the config/address_constants.yaml file?

fablet commented 4 years ago

It looks like you are just calling the tests directly, rather than using tox. If you look at the tox.ini you can see that it specifies a testing environmental variable for ADDRESS_CONFIG_DIR using setenv.

Per the "Installation" instructions in the README, "To use a custom constants yaml, set the ADDRESS_CONFIG_DIR environment variable with the full path to the directory containing your address_constants.yaml file"

The tests that are failing for you are testing the behavior of being able to use custom constants. So it is a combination of the missing config/address_constants.yaml and the environment variable not being set during the test run

zyxue commented 4 years ago

Thank you! I'm not too familiar with tox, but I see why now, and I can make it work with

ADDRESS_CONFIG_DIR=${PWD}/scourgify/tests/config pytest scourgify/tests
fablet commented 4 years ago

Excellent! I'm glad we were able to work through it!