Commit d7bd2f76 authored by Marco Cavalli's avatar Marco Cavalli
Browse files

test

parent 7b772ae1
Loading
Loading
Loading
Loading
Loading

.gitlab-ci.yml

0 → 100644
+60 −0
Original line number Diff line number Diff line
stages:
  - build
  - test

variables:
  DOCKER_DRIVER: overlay2
  IMAGE_NAME: registry.gitlab.com/$CI_PROJECT_PATH/app
  DOCKER_TLS_CERTDIR: ""

build_image:
  stage: build
  image: docker:25.0.3
  services:
    - docker:25.0.3-dind
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      changes:
        - Dockerfile
        - requirements.txt

    - if: '$CI_COMMIT_BRANCH == "develop"'
      changes:
        - Dockerfile
        - requirements.txt
    - when: never

  script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY

    - docker pull $IMAGE_NAME:cache || true

    - docker build \
        --cache-from=$IMAGE_NAME:cache \
        -t $IMAGE_NAME:$CI_COMMIT_SHA \
        -t $IMAGE_NAME:cache \
        .

    - docker push $IMAGE_NAME:$CI_COMMIT_SHA
    - docker push $IMAGE_NAME:cache

  artifacts:
    expire_in: 1 week
    reports:
      dotenv: build.env
  after_script:
    - echo "IMAGE_TAG=$CI_COMMIT_SHA" >> build.env

test_documentation:
  stage: test
  image: $IMAGE_NAME:$CI_COMMIT_SHA
  needs: ["build_image"]
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
    - if: '$CI_COMMIT_BRANCH == "develop"'
    - when: never
  variables:
    GIT_STRATEGY: clone 
  script:
    - ls -la
    - python -m unittest discover -s ./doc/tests -t ./doc
 No newline at end of file

Dockerfile

0 → 100644
+8 −0
Original line number Diff line number Diff line
FROM python:3.12

WORKDIR /app
COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

CMD ["python", "-m", "unittest", "discover", "-s", "./doc/tests", "-t", "./doc"]
 No newline at end of file

requirements.txt

0 → 100644
+10 −0
Original line number Diff line number Diff line
# python3.11 project
robotframework==6.1.1
robotframework-jsonlibrary==0.5
robotframework-requests==0.9.6
deepdiff==6.7.1
prettydiff==0.1.0
robotframework-httpctrl==0.3.1
robotframework-tidy==4.11.0
paho-mqtt==1.6.1
robotframework-mqttlibrary==0.7.1.post3

test_mymodule.py

0 → 100644
+53 −0
Original line number Diff line number Diff line
import unittest


class TestMyModule(unittest.TestCase):
    
    def setUp(self):
        """Set up test fixtures before each test method"""
        pass
    
    def tearDown(self):
        """Clean up after each test method"""
        pass
    
    def test_addition(self):
        """Test basic addition"""
        result = 2 + 2
        self.assertEqual(result, 4)
    
    def test_subtraction(self):
        """Test basic subtraction"""
        result = 5 - 3
        self.assertEqual(result, 2)
    
    def test_multiplication(self):
        """Test basic multiplication"""
        result = 3 * 4
        self.assertEqual(result, 12)
    
    def test_division(self):
        """Test basic division"""
        result = 10 / 2
        self.assertEqual(result, 5)
    
    def test_string_concatenation(self):
        """Test string concatenation"""
        result = "Hello" + " " + "World"
        self.assertEqual(result, "Hello World")
    
    def test_list_operations(self):
        """Test list operations"""
        my_list = [1, 2, 3]
        my_list.append(4)
        self.assertEqual(len(my_list), 4)
        self.assertIn(4, my_list)
    
    def test_exception_handling(self):
        """Test exception is raised"""
        with self.assertRaises(ZeroDivisionError):
            result = 1 / 0


if __name__ == '__main__':
    unittest.main()
 No newline at end of file