Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

Commit

Permalink
Runs python2 unit tests for real now (#38)
Browse files Browse the repository at this point in the history
* enabled python2 tests to run
  • Loading branch information
s1113950 committed Mar 27, 2019
1 parent 38c491d commit 42adc93
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 38 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ test_data/
__pycache__/
*.idea
.coverage
*.pyc
48 changes: 24 additions & 24 deletions tensorflow_quantization/Makefile
Expand Up @@ -15,40 +15,39 @@
# SPDX-License-Identifier: EPL-2.0
#

# Set PY_VERSION to 2 or 3 to create different envs without using tox
PY_VERSION ?= $(shell python --version 2>&1 | cut -c8)

PY_VERSION := 2
# if py_version is 2, use virtualenv, else python3 venv
VIRTUALENV_EXE=$(if $(subst 2,,$(PY_VERSION)),python3 -m venv,virtualenv)
VIRTUALENV_DIR=$(if $(subst 2,,$(PY_VERSION)),.venv3,.venv)
ACTIVATE="$(VIRTUALENV_DIR)/bin/activate"
# Get OS so as to not run cpplint if on a Mac
# TODO: is Windows supported?
OS := $(shell uname)

.PHONY: venv

all: venv

$(ACTIVATE):
@test -d $(VIRTUALENV_DIR) || $(VIRTUALENV_EXE) $(VIRTUALENV_DIR)
@touch $(ACTIVATE)
venv:
@echo "Creating Python${PY_VERSION} virtualenv"
@tox -e py${PY_VERSION}-venv

venv: $(ACTIVATE)
@echo -n "Using "
@. $(ACTIVATE) && python --version

venv2: venv

venv3: PY_VERSION=3
venv3: $(ACTIVATE)
@echo -n "Using "
@. $(ACTIVATE) && python3 --version
venv-all: venv
@echo "Creating Python2 and 3 virtualenv in .venv and .venv3 dirs"
@tox -e py2-venv -e py3-venv

tox:
tox


ifeq ($(OS), Darwin)
cpplint:
@echo "Not running cpp lint tests on Mac, it will fail"
else
# Runs Google required linting checks
# buildifier doesn't write out to files, it just edits them in place
# so we'll check if a `git diff` shows anything
cpplint:
@echo "Running lint checks for c++ code. NOTE: Google check can't run on Mac."

find . -name "*.cc" | xargs -n1 tests/cpplint.py
find . -name "*.cc" | xargs -I '{}' \
sh -c 'tests/clang-format -style=Google {} > {}-temp.cc; \
Expand All @@ -60,30 +59,31 @@ cpplint:
sh -c 'tests/buildifier {}; \
git diff {} | tee -a diffs.txt'; \
sh -c "if [ -s diffs.txt ]; then rm diffs.txt && exit 1; else rm diffs.txt; fi"
endif

lint: cpplint
@echo "Running style check..."
tox -e py2.7-flake8 -e py3-flake8
tox -e py2-lint -e py3-lint

lint2: cpplint
@echo "Running style check..."
tox -e py2.7-flake8
tox -e py2-lint

lint3: cpplint
@echo "Running style check..."
tox -e py3-flake8
tox -e py3-lint

unit_test:
@echo "Running unit tests..."
tox -e py2.7-py.test -e py3-py.test
tox -e py2-unit -e py3-unit

unit_test2:
@echo "Running unit tests python 2..."
tox -e py2.7-py.test
tox -e py2-unit

unit_test3:
@echo "Running unit tests python 3..."
tox -e py3-py.test
tox -e py3-unit

integration_test:
@echo "Running integration tests..."
Expand Down
@@ -1,4 +1,3 @@
flake8
numpy
pytest
pytest-cov
Expand Down
Empty file.
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

import pytest
from mock import MagicMock

Expand Down
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

import pytest
from mock import MagicMock, mock_open

Expand Down
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
49 changes: 36 additions & 13 deletions tensorflow_quantization/tox.ini
@@ -1,20 +1,51 @@
# Copyright (c) 2019 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: EPL-2.0
#

[tox]
envlist = py{2.7,3}-{flake8,py.test}
envlist = py{2,3}-{venv,lint,unit}
skipsdist=True

[flake8]
ignore = C901,W504
tee = True
inline-quotes = double
max-line-length=120
max-complexity=12
exclude = .cache,.tox,__pycache__,.pytest_cache,*.pyc,.venv,.mypy_cache,tests/cpplint.py

[testenv]
setenv = PYTHONPATH = {toxinidir}/quantization{:}{toxinidir}
skip_install=True
envdir =
py2: {toxworkdir}/.venv
py3: {toxworkdir}/.venv3
deps =
-rrequirements-tests.txt
lint: flake8
unit: -rrequirements-unit-tests.txt

skip_install=True
passenv =
PYTHONPATH
http_proxy
https_proxy
no_proxy
commands =
flake8: flake8 tests
py.test: py.test {env:TESTOPTS:} {env:TESTFILES:{toxinidir}/tests/unit}
lint: flake8 tests
unit: py.test {env:TESTOPTS:} {env:TESTFILES:{toxinidir}/tests/unit}


[pytest]
addopts =
Expand All @@ -37,11 +68,3 @@ omit =
.tox/*
.pytest_cache/*
__pycache__/*

[flake8]
ignore = C901,W504
tee = True
inline-quotes = double
max-line-length=120
max-complexity=12
exclude = .cache,.tox,__pycache__,.pytest_cache,*.pyc,.venv,.mypy_cache,tests/cpplint.py

0 comments on commit 42adc93

Please sign in to comment.