Skip to content

Commit 7d9506d

Browse files
Abstract class enforced (#521)
* gitignore cleaned and re-organised * LayerConfig Abstract Class enforced as Abstract * LayersConfig unittest added * Py2 and Py3 compatibility issue fixed
1 parent 250c6f3 commit 7d9506d

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

.gitignore

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
*.npz
33
*.pyc
44
*~
5+
56
.DS_Store
67
.idea
78
.spyproject/
9+
.pytest_cache/
10+
11+
venv/
812
build/
9-
dist
13+
data/
14+
dist/
1015
docs/_build
1116
tensorlayer.egg-info
12-
tensorlayer/__pacache__
13-
venv/
14-
.pytest_cache/
17+
tensorlayer/__pycache__
18+
1519
update_tl.bat
1620
update_tl.py

tensorlayer/layers/core.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# -*- coding: utf-8 -*-
22

3+
import six
34
import time
5+
from abc import ABCMeta, abstractmethod
46

57
import numpy as np
68
import tensorflow as tf
@@ -38,10 +40,16 @@
3840
]
3941

4042

41-
class LayersConfig:
43+
@six.add_metaclass(ABCMeta)
44+
class LayersConfig(object):
45+
4246
tf_dtype = tf.float32 # TensorFlow DType
4347
set_keep = {} # A dictionary for holding tf.placeholders
4448

49+
@abstractmethod
50+
def __init__(self):
51+
pass
52+
4553

4654
try: # For TF12 and later
4755
TF_GRAPHKEYS_VARIABLES = tf.GraphKeys.GLOBAL_VARIABLES

tests/test_layers_core.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
import tensorlayer as tl
77

88

9+
class Core_Helpers_Test(unittest.TestCase):
10+
11+
def test_LayersConfig(self):
12+
with self.assertRaises(TypeError):
13+
tl.layers.LayersConfig()
14+
15+
self.assertIsInstance(tl.layers.LayersConfig.tf_dtype, tf.DType)
16+
self.assertIsInstance(tl.layers.LayersConfig.set_keep, dict)
17+
18+
919
class Layer_Core_Test(unittest.TestCase):
1020

1121
@classmethod

0 commit comments

Comments
 (0)