Don't exit 0 with linter errors (#26)

* Cosmetic: Make linter happy

* Fix test safe log test

Co-authored-by: Lukas Wutschitz <lukas.wutschitz@microsoft.com>
This commit is contained in:
Lukas Wutschitz 2021-11-17 13:59:32 +00:00 коммит произвёл GitHub
Родитель d83df3af60
Коммит 77783cae78
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 14 добавлений и 16 удалений

2
.github/workflows/test-package.yml поставляемый
Просмотреть файл

@ -34,7 +34,7 @@ jobs:
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
flake8 . --count --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest

Просмотреть файл

@ -4,8 +4,6 @@
import numpy as np
from typing import Tuple
from scipy import optimize
from .other_accountants import RDP
from . import discretisers
from . import composers

Просмотреть файл

@ -102,7 +102,7 @@ class PoissonSubsampledGaussianMechanism(PrivacyRandomVariable):
def cdf(self, t):
sigma = self.sigma
p = self.p
z = np.where(t>0, log((p-1)/p + exp(t)/p), log((p-1)/p + exp(t)/p))
z = np.where(t > 0, log((p-1)/p + exp(t)/p), log((p-1)/p + exp(t)/p))
return np.where(t > log(1 - p), (
(1.0/2.0) * p * (-erfc(np.double((1.0/4.0)*M_SQRT2*(2*pow(sigma, 2)*z - 1)/sigma))) -
1.0/2.0*(p - 1) * (-erfc(np.double((1.0/4.0)*M_SQRT2*(2*pow(sigma, 2)*z + 1)/sigma))) + 1
@ -115,7 +115,7 @@ class PoissonSubsampledGaussianMechanism(PrivacyRandomVariable):
"""
Compute RDP of this mechanism of order alpha
Based on Google's TF Privacy: https://github.com/tensorflow/privacy/blob/master/tensorflow_privacy/privacy/analysis/rdp_accountant.py
Based on Google's TF Privacy: https://github.com/tensorflow/privacy/blob/master/tensorflow_privacy/privacy/analysis/rdp_accountant.py # noqa: E501
"""
if self.p == 0:
return 0

Просмотреть файл

@ -1,7 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from typing import AsyncContextManager
import scipy
import math
import pytest
@ -10,9 +9,10 @@ import sys
from prv_accountant.privacy_random_variables import PoissonSubsampledGaussianMechanism, log, PrivacyRandomVariableTruncated
def test_safe_log():
assert np.isnan(log(-1)) == True
assert np.isneginf(log(0)) == True
assert np.isnan(log(-1)) == True # noqa: E712
assert np.isneginf(log(0)) == True # noqa: E712
assert log(1) == pytest.approx(0)