Ruff pandas vet (#10281)

* Python linting: Add ruff rules for Pandas-vet and Pytest-style

* updating DIRECTORY.md

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Christian Clauss
2023-10-11 20:30:02 +02:00
committed by GitHub
parent d5323dbaee
commit 3f094fe49d
28 changed files with 260 additions and 241 deletions

View File

@@ -1,5 +1,7 @@
import unittest
import pytest
from knapsack import greedy_knapsack as kp
@@ -16,7 +18,7 @@ class TestClass(unittest.TestCase):
profit = [10, 20, 30, 40, 50, 60]
weight = [2, 4, 6, 8, 10, 12]
max_weight = 100
self.assertEqual(kp.calc_profit(profit, weight, max_weight), 210)
assert kp.calc_profit(profit, weight, max_weight) == 210
def test_negative_max_weight(self):
"""
@@ -26,7 +28,7 @@ class TestClass(unittest.TestCase):
# profit = [10, 20, 30, 40, 50, 60]
# weight = [2, 4, 6, 8, 10, 12]
# max_weight = -15
self.assertRaisesRegex(ValueError, "max_weight must greater than zero.")
pytest.raises(ValueError, match="max_weight must greater than zero.")
def test_negative_profit_value(self):
"""
@@ -36,7 +38,7 @@ class TestClass(unittest.TestCase):
# profit = [10, -20, 30, 40, 50, 60]
# weight = [2, 4, 6, 8, 10, 12]
# max_weight = 15
self.assertRaisesRegex(ValueError, "Weight can not be negative.")
pytest.raises(ValueError, match="Weight can not be negative.")
def test_negative_weight_value(self):
"""
@@ -46,7 +48,7 @@ class TestClass(unittest.TestCase):
# profit = [10, 20, 30, 40, 50, 60]
# weight = [2, -4, 6, -8, 10, 12]
# max_weight = 15
self.assertRaisesRegex(ValueError, "Profit can not be negative.")
pytest.raises(ValueError, match="Profit can not be negative.")
def test_null_max_weight(self):
"""
@@ -56,7 +58,7 @@ class TestClass(unittest.TestCase):
# profit = [10, 20, 30, 40, 50, 60]
# weight = [2, 4, 6, 8, 10, 12]
# max_weight = null
self.assertRaisesRegex(ValueError, "max_weight must greater than zero.")
pytest.raises(ValueError, match="max_weight must greater than zero.")
def test_unequal_list_length(self):
"""
@@ -66,9 +68,7 @@ class TestClass(unittest.TestCase):
# profit = [10, 20, 30, 40, 50]
# weight = [2, 4, 6, 8, 10, 12]
# max_weight = 100
self.assertRaisesRegex(
IndexError, "The length of profit and weight must be same."
)
pytest.raises(IndexError, match="The length of profit and weight must be same.")
if __name__ == "__main__":

View File

@@ -20,12 +20,12 @@ class Test(unittest.TestCase):
val = [0]
w = [0]
c = len(val)
self.assertEqual(k.knapsack(cap, w, val, c), 0)
assert k.knapsack(cap, w, val, c) == 0
val = [60]
w = [10]
c = len(val)
self.assertEqual(k.knapsack(cap, w, val, c), 0)
assert k.knapsack(cap, w, val, c) == 0
def test_easy_case(self):
"""
@@ -35,7 +35,7 @@ class Test(unittest.TestCase):
val = [1, 2, 3]
w = [3, 2, 1]
c = len(val)
self.assertEqual(k.knapsack(cap, w, val, c), 5)
assert k.knapsack(cap, w, val, c) == 5
def test_knapsack(self):
"""
@@ -45,7 +45,7 @@ class Test(unittest.TestCase):
val = [60, 100, 120]
w = [10, 20, 30]
c = len(val)
self.assertEqual(k.knapsack(cap, w, val, c), 220)
assert k.knapsack(cap, w, val, c) == 220
if __name__ == "__main__":