From 1429bf423dd25259bd52cbd7ca01e4d471c1bb35 Mon Sep 17 00:00:00 2001 From: Peng Cheng Date: Tue, 26 Jan 2021 10:42:51 +0800 Subject: [PATCH] CI: Initialization - Add Azure Pipelines for checking format and running pytest (#2) **Description** Init Azure Pipelines for checking format and running pytest. **Major Revision** - Add azure-pipelines.yml for running Azure Pipelines. - Add Dockerfile and test/test_example.py for checking format and running pytest. --- azure-pipelines.yml | 26 ++++++++++++++++++++++++++ test.dockerfile | 27 +++++++++++++++++++++++++++ tests/test_example.py | 12 ++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 azure-pipelines.yml create mode 100644 test.dockerfile create mode 100644 tests/test_example.py diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 00000000..a5b361d5 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,26 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT license. + +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +trigger: +- master +- dev + +resources: +- repo: self + +variables: + tag: '$(Build.BuildId)' + +steps: + - task: Docker@2 + displayName: Build uni-test Docker for SuperBench testing + inputs: + command: build + dockerfile: '$(Build.SourcesDirectory)/test.dockerfile' + tags: | + $(tag) diff --git a/test.dockerfile b/test.dockerfile new file mode 100644 index 00000000..6b12fd3b --- /dev/null +++ b/test.dockerfile @@ -0,0 +1,27 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT license. + +FROM ubuntu:18.04 + +# Install the python3.7 and pip +RUN apt-get update && apt-get install -y \ + python3.7-dev \ + python3-pip + +# Change default python3 version to python3.7 +RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 && \ + update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 10 + +# Upgrade pip and instll flake8 and pytest +RUN python3 -m pip install --upgrade pip && \ + python3 -m pip install flake8 pytest + +# Create workspace +WORKDIR /superbench +COPY . /superbench + +# Check code format using flake8 +RUN python3 -m flake8 + +# Install library and run pytest +RUN python3 -m pytest -v diff --git a/tests/test_example.py b/tests/test_example.py new file mode 100644 index 00000000..dbd432ba --- /dev/null +++ b/tests/test_example.py @@ -0,0 +1,12 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT license. + +# content of test_sample.py +# get it from https://docs.pytest.org/en/stable/ + +def inc(x): + return x + 1 + + +def test_answer(): + assert inc(3) == 4