PR#1168: remove shebang in context module
Merges #1168 https://pagure.io/koji/pull-request/1168
This commit is contained in:
commit
31b9e14dfe
2 changed files with 41 additions and 35 deletions
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/python2
|
||||
# Copyright (c) 2005-2014 Red Hat, Inc.
|
||||
#
|
||||
# Koji is free software; you can redistribute it and/or
|
||||
|
|
@ -26,7 +25,6 @@
|
|||
|
||||
from __future__ import absolute_import
|
||||
import six.moves._thread
|
||||
from six.moves import range
|
||||
import six
|
||||
|
||||
class _data(object):
|
||||
|
|
@ -80,36 +78,3 @@ class ThreadLocal(object):
|
|||
|
||||
|
||||
context = ThreadLocal()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
#testing
|
||||
|
||||
#context.foo = 1
|
||||
#context.bar = 2
|
||||
print(context)
|
||||
#del context.bar
|
||||
print(context)
|
||||
|
||||
import random
|
||||
import time
|
||||
def test():
|
||||
context.foo = random.random()
|
||||
time.sleep(1.5+random.random())
|
||||
context._threadclear()
|
||||
print(context)
|
||||
|
||||
for x in range(1, 10):
|
||||
six.moves._thread.start_new_thread(test, ())
|
||||
|
||||
time.sleep(4)
|
||||
print('')
|
||||
print(context)
|
||||
|
||||
context.foo = 1
|
||||
context.bar = 2
|
||||
print(context.foo, context.bar)
|
||||
print(context)
|
||||
context._threadclear()
|
||||
print(context)
|
||||
|
|
|
|||
41
tests/test_lib/test_context.py
Normal file
41
tests/test_lib/test_context.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
from __future__ import absolute_import
|
||||
import six
|
||||
import time
|
||||
import random
|
||||
try:
|
||||
import unittest2 as unittest
|
||||
except ImportError:
|
||||
import unittest
|
||||
|
||||
from koji.context import context
|
||||
|
||||
|
||||
class TestContext(unittest.TestCase):
|
||||
|
||||
def test_context(self):
|
||||
context.foo = 1
|
||||
|
||||
def test():
|
||||
foo = random.random()
|
||||
context.foo = foo
|
||||
time.sleep(0.5 + random.random())
|
||||
print(context)
|
||||
self.assertEqual(context.foo, foo)
|
||||
context._threadclear()
|
||||
self.assertFalse(hasattr(context, 'foo'))
|
||||
|
||||
for x in range(1, 10):
|
||||
six.moves._thread.start_new_thread(test, ())
|
||||
|
||||
time.sleep(0.5)
|
||||
for i in range(10):
|
||||
time.sleep(0.2 + random.random())
|
||||
self.assertEqual(context.foo, 1)
|
||||
|
||||
context.foo = 2
|
||||
context.bar = 3
|
||||
self.assertEqual(context.foo, 2)
|
||||
self.assertEqual(context.bar, 3)
|
||||
context._threadclear()
|
||||
self.assertFalse(hasattr(context, 'foo'))
|
||||
self.assertFalse(hasattr(context, 'bar'))
|
||||
Loading…
Add table
Add a link
Reference in a new issue