-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from dana-yaish/test-bazel
test bazel
- Loading branch information
Showing
11 changed files
with
158 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#https://github.com/bazelbuild/rules_python - for using py rules | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
http_archive( | ||
name = "rules_python", | ||
sha256 = "84aec9e21cc56fbc7f1335035a71c850d1b9b5cc6ff497306f84cced9a769841", | ||
strip_prefix = "rules_python-0.23.1", | ||
url = "https://github.com/bazelbuild/rules_python/releases/download/0.23.1/rules_python-0.23.1.tar.gz", | ||
) | ||
|
||
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains") | ||
|
||
py_repositories() | ||
|
||
python_register_toolchains( | ||
name = "python39", | ||
python_version = "3.9", | ||
register_coverage_tool = True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
py_library( | ||
name="calculator", | ||
srcs=["calculator.py"], | ||
|
||
) | ||
|
||
py_test( | ||
name="test_calculator", | ||
srcs=["test_calculator.py"], | ||
deps = [ | ||
"//app/projectA:calculator", | ||
] | ||
) | ||
|
||
exports_files(["codecov_wrapper.sh"]) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#/bin/bash | ||
|
||
# `bazel coverage --run_under foo :bar` basically translates to: | ||
# foo pytest --cov bar/src/a.py bar/src/b.py | ||
# We want to run that `pytest` command unmodified, as below: | ||
"$@" | ||
|
||
# codecov doesn't recognise pylcov.dat as a coverage report, renaming it to lcov.dat so codecov can acknowledge it | ||
mv $COVERAGE_DIR/pylcov.dat $COVERAGE_DIR/lcov.dat | ||
|
||
# uploading coverage | ||
codecovcli -v create-commit -t $CODECOV_TOKEN | ||
codecovcli -v create-report -t $CODECOV_TOKEN | ||
codecovcli -v do-upload -t $CODECOV_TOKEN -s $COVERAGE_DIR | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
from app.projectA.calculator import Calculator | ||
|
||
import unittest | ||
|
||
|
||
|
||
class TestMethods(unittest.TestCase): | ||
def test_add(self): | ||
self.assertEqual(True, True) | ||
|
||
def test_add(self): | ||
self.assertEqual(Calculator.add(1, 2), 3.0) | ||
self.assertEqual(Calculator.add(1.0, 2.0), 3.0) | ||
self.assertEqual(Calculator.add(0, 2.0), 2.0) | ||
self.assertEqual(Calculator.add(2.0, 0), 2.0) | ||
self.assertEqual(Calculator.add(-4, 2.0), -2.0) | ||
|
||
def test_subtract(self): | ||
self.assertEqual(Calculator.subtract(1, 2) , -1.0) | ||
self.assertEqual(Calculator.subtract(2, 1) , 1.0) | ||
self.assertEqual(Calculator.subtract(1.0, 2.0) , -1.0) | ||
self.assertEqual(Calculator.subtract(0, 2.0) , -2.0) | ||
self.assertEqual(Calculator.subtract(2.0, 0.0) , 2.0) | ||
self.assertEqual(Calculator.subtract(-4, 2.0) , -6.0) | ||
|
||
def test_multiply(self): | ||
self.assertEqual(Calculator.multiply(1, 2) , 2.0) | ||
self.assertEqual(Calculator.multiply(1.0, 2.0) , 2.0) | ||
self.assertEqual(Calculator.multiply(0, 2.0) , 0.0) | ||
self.assertEqual(Calculator.multiply(2.0, 0.0) , 0.0) | ||
self.assertEqual(Calculator.multiply(-4, 2.0) , -8.0) | ||
|
||
def test_divide(self): | ||
self.assertEqual(Calculator.divide(1.0, 2.0) , 0.5) | ||
self.assertEqual(Calculator.divide(0, 2.0) , 0) | ||
self.assertEqual(Calculator.divide(-4, 2.0) , -2.0) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
py_library( | ||
name="adder", | ||
srcs=["adder.py"], | ||
|
||
) | ||
|
||
py_test( | ||
name="test_adder", | ||
srcs=["test_adder.py"], | ||
deps = [ | ||
"//app/projectB:adder", | ||
] | ||
) | ||
|
||
exports_files(["codecov_wrapper.sh"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class Adder: | ||
def add(self, x, y): | ||
return x + y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#/bin/bash | ||
|
||
# `bazel coverage --run_under foo :bar` basically translates to: | ||
# foo pytest --cov bar/src/a.py bar/src/b.py | ||
# We want to run that `pytest` command unmodified, as below: | ||
"$@" | ||
|
||
# codecov doesn't recognise pylcov.dat as a coverage report, renaming it to lcov.dat so codecov can acknowledge it | ||
mv $COVERAGE_DIR/pylcov.dat $COVERAGE_DIR/lcov.dat | ||
|
||
# uploading coverage | ||
codecovcli -v create-commit -t $CODECOV_TOKEN | ||
codecovcli -v create-report -t $CODECOV_TOKEN | ||
codecovcli -v do-upload -t $CODECOV_TOKEN -s $COVERAGE_DIR | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import unittest | ||
|
||
from app.projectB.adder import Adder | ||
|
||
|
||
class TestAdder(unittest.TestCase): | ||
def test_adder(self): | ||
assert 2 + 3.0 == Adder().add(2, 3) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file was deleted.
Oops, something went wrong.