diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..0cadc27 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,42 @@ +kind: pipeline +type: docker +name: testPythonconnect4 + +trigger: + event: + - push +steps: + - name: test + image: python:3.7 + commands: + - pip install parameterized + - python -m unittest discover -v -p *_ut.py + + - name: code-analysis + #image: aosapps/drone-sonar-plugin:latest + #image: python:3.7 + image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-dronesonarplugin-python37 + commands: + #- pip install nose + #- pip install coverage + #- pip install parameterized + #- nosetests --with-coverage --cover-branches --cover-xml + - nosetests connect4/test/*_ut.py --with-coverage --cover-branches --cover-xml + #- cat coverage.xml + #- export + #- env + #- echo $PLUGIN_SONAR_TOKEN + #- sed -i 's/filename="/filename=".\//g' coverage-reports/coverage-test.xml + #- sonar-runner + - /opt/sonar-scanner/bin/sonar-scanner -Dsonar.login=$PLUGIN_SONAR_TOKEN + settings: + # accessible en ligne de commande par $${PLUGIN_SONAR_HOST} + sonar_host: https://codefirst.iut.uca.fr/sonar/ + # accessible en ligne de commande par $${PLUGIN_SONAR_TOKEN} + sonar_token: + from_secret: SECRET_SONAR_LOGIN + sonar.python.version: 3 + + + + \ No newline at end of file diff --git a/connect4/__init__.py b/connect4/__init__.py new file mode 100644 index 0000000..4cf83ae --- /dev/null +++ b/connect4/__init__.py @@ -0,0 +1 @@ +__all__ = ['src/player'] \ No newline at end of file diff --git a/connect4/src/__init__.py b/connect4/src/__init__.py new file mode 100644 index 0000000..c54c549 --- /dev/null +++ b/connect4/src/__init__.py @@ -0,0 +1 @@ +__all__ = ['player'] \ No newline at end of file diff --git a/src/board.py b/connect4/src/board.py similarity index 100% rename from src/board.py rename to connect4/src/board.py diff --git a/src/player.py b/connect4/src/player.py similarity index 100% rename from src/player.py rename to connect4/src/player.py diff --git a/connect4/src/rules.py b/connect4/src/rules.py new file mode 100644 index 0000000..1c3ad19 --- /dev/null +++ b/connect4/src/rules.py @@ -0,0 +1,25 @@ +from connect4.src.board import Board + +class Rules: + def __init__(self): + + self.nb_row = 6 + self.nb_col = 7 + + def check_board_size(self, board): + """ Checks if the board size is correct. + Entries: + self: the Rules class itself + board -> Board: a board + Output: + correct -> Bool: if True, the board size is correct + """ + correct = False + + + if self.nb_col == board.nbcol and self.nb_row == board.nbrow : + correct = True + else: + correct = False + + return correct diff --git a/__init__.py b/connect4/test/__init__.py similarity index 100% rename from __init__.py rename to connect4/test/__init__.py diff --git a/test/player_ut.py b/connect4/test/player_ut.py similarity index 65% rename from test/player_ut.py rename to connect4/test/player_ut.py index 4b99a1d..b605286 100644 --- a/test/player_ut.py +++ b/connect4/test/player_ut.py @@ -1,9 +1,10 @@ import unittest -from parametrized import parametrized -from src.player import Players +from parameterized import parameterized +from ..src.player import Players +# from player import Players class TestPlayer(unittest.TestCase): - @parametrized.expand([ + @parameterized.expand([ ("joe", "jonny", True), (1, "jonny", False), ("joe", 15, False), @@ -11,8 +12,9 @@ class TestPlayer(unittest.TestCase): def testString(self, name1, name2, no_exception): try: players = Players(name1=name1, name2=name2) + self.assertTrue(no_exception) except: self.assertFalse(no_exception) if __name__=='__main__': - test_player = TestPlayer() \ No newline at end of file + unittest.main() \ No newline at end of file diff --git a/connect4/test/rules_ut.py b/connect4/test/rules_ut.py new file mode 100644 index 0000000..2346a46 --- /dev/null +++ b/connect4/test/rules_ut.py @@ -0,0 +1,25 @@ +import unittest +from parameterized import parameterized + +from ..src.rules import Rules +from ..src.board import Board + +class TestRules(unittest.TestCase): + @parameterized.expand([ + (6, 7, True), + (10, 10, False), + ('6', '7', False), + (7, '1', False), + ('1', 6, False), + ]) + def test_check_board_size(self, row, col, no_exception): + rules = Rules() + board = Board(row, col) + + if no_exception: + self.assertTrue(rules.check_board_size(board)) + else: + self.assertFalse(rules.check_board_size(board)) + +if __name__ == "__main__": + unittest.main() \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..303bbbb --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,11 @@ +sonar.projectKey=connect4 +sonar.projectName=Connect4 Workshop +sonar.projectVersion=1.0 +sonar.sources=connect4/src +sonar.tests=connect4/test +sonar.language=py +sonar.sourceEncoding=UTF-8 +sonar.python.xunit.reportPath=nosetests.xml +sonar.python.coverage.reportPath=coverage.xml +sonar.python.coveragePlugin=cobertura +# sonar.inclusions="*_ut.py" \ No newline at end of file diff --git a/src/__init__.py b/src/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/test/__init__.py b/test/__init__.py deleted file mode 100644 index e69de29..0000000