Esempio n. 1
0
    def test_when_valid_file_with_content_then_returns_expected_geojson(self):
        # 1. Set up test data
        file_path = (
            TestUtils.get_local_test_data_dir("maskoutputfile_test_data") /
            "mask_points.geojson")

        # 2. Verify initial expectations
        assert file_path.exists(), f"File not found at {file_path}"

        # 2. Read data
        read_geojson = MaskOutputFile.read_mask_output_file(str(file_path))

        # 3. Verify final expectations
        assert read_geojson, "" + "No geojson data was generated."
        assert read_geojson.is_valid, "" + "The geojson data is not valid."
Esempio n. 2
0
    def test_when_valid_file_with_no_content_then_returns_expected_geojson(
            self, file_name):
        # 1. Set up test data
        file_path: Path = (
            TestUtils.get_local_test_data_dir("maskoutputfile_test_data") /
            file_name)

        expected_geojson = geojson.FeatureCollection(None)
        assert file_path.is_file(), "File not found at {}".format(file_path)

        # 2. Read data
        read_geojson = MaskOutputFile.read_mask_output_file(str(file_path))

        # 3. Verify final expectations
        assert read_geojson, "No geojson data was generated."
        assert (read_geojson == expected_geojson
                ), f"Expected {expected_geojson} but got {read_geojson}"
Esempio n. 3
0
    def test_when_invalid_file_path_given_then_emtpy_geojson(
            self, file_path_name):
        # 1. Set up test data
        read_geojson = None

        # 2. Set up initial expectations
        expected_geojson = geojson.FeatureCollection(None)

        # 3. Read data
        try:
            read_geojson = MaskOutputFile.read_mask_output_file(file_path_name)
        except:
            pytest.fail("Exception thrown but not expected.")

        # 4. Verify final expectations
        assert read_geojson, "" + "No geojson data was generated."
        assert read_geojson == expected_geojson, "" + "Expected {} but got {}".format(
            expected_geojson, read_geojson)
Esempio n. 4
0
    def test_when_file_path_wrong_extension_then_raise_exception(self):
        # 1. Set up test data
        file_path = (
            TestUtils.get_local_test_data_dir("maskoutputfile_test_data") /
            "test_file.wrongextension")
        read_geojson_data = None

        # 2. Set expectations
        assert file_path.exists(
        ), "" + "File {} could not be found.".format(file_path)
        expected_error = (
            "" + "Invalid file path extension, should be .json or .geojson.")

        # 3. Run test
        with pytest.raises(IOError) as e_info:
            read_geojson_data = MaskOutputFile.read_mask_output_file(
                str(file_path))

        # 4. Verify final expectations
        assert not read_geojson_data
        error_message = str(e_info.value)
        assert error_message == expected_error, (
            "" + "Expected exception message {},".format(expected_error) +
            "retrieved {}".format(error_message))