1#!/usr/bin/python 2 3############################################################################# 4## 5## Copyright (C) 2016 The Qt Company Ltd. 6## Contact: https://www.qt.io/licensing/ 7## 8## This file is part of the test suite of Qt for Python. 9## 10## $QT_BEGIN_LICENSE:GPL-EXCEPT$ 11## Commercial License Usage 12## Licensees holding valid commercial Qt licenses may use this file in 13## accordance with the commercial license agreement provided with the 14## Software or, alternatively, in accordance with the terms contained in 15## a written agreement between you and The Qt Company. For licensing terms 16## and conditions see https://www.qt.io/terms-conditions. For further 17## information use the contact form at https://www.qt.io/contact-us. 18## 19## GNU General Public License Usage 20## Alternatively, this file may be used under the terms of the GNU 21## General Public License version 3 as published by the Free Software 22## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 23## included in the packaging of this file. Please review the following 24## information to ensure the GNU General Public License requirements will 25## be met: https://www.gnu.org/licenses/gpl-3.0.html. 26## 27## $QT_END_LICENSE$ 28## 29############################################################################# 30 31'''Test cases for overloads involving static and non-static versions of a method.''' 32 33import os 34import sys 35import unittest 36 37sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 38from init_paths import init_test_paths 39init_test_paths(False) 40 41from PySide2.QtCore import QFile 42 43class StaticNonStaticMethodsTest(unittest.TestCase): 44 '''Test cases for overloads involving static and non-static versions of a method.''' 45 46 def setUp(self): 47 filename = 'somefile%d.txt' % os.getpid() 48 self.existing_filename = os.path.join(os.path.curdir, filename) 49 self.delete_file = False 50 if not os.path.exists(self.existing_filename): 51 f = open(self.existing_filename, 'w') 52 for line in range(10): 53 f.write('sbrubbles\n') 54 f.close() 55 self.delete_file = True 56 57 self.non_existing_filename = os.path.join(os.path.curdir, 'inexistingfile.txt') 58 i = 0 59 while os.path.exists(self.non_existing_filename): 60 i += 1 61 filename = 'inexistingfile-%d.txt' % i 62 self.non_existing_filename = os.path.join(os.path.curdir, filename) 63 64 def tearDown(self): 65 if self.delete_file: 66 os.remove(self.existing_filename) 67 68 def testCallingStaticMethodWithClass(self): 69 '''Call static method using class.''' 70 self.assertTrue(QFile.exists(self.existing_filename)) 71 self.assertFalse(QFile.exists(self.non_existing_filename)) 72 73 def testCallingStaticMethodWithInstance(self): 74 '''Call static method using instance of class.''' 75 f = QFile(self.non_existing_filename) 76 self.assertTrue(f.exists(self.existing_filename)) 77 self.assertFalse(f.exists(self.non_existing_filename)) 78 79 def testCallingInstanceMethod(self): 80 '''Call instance method.''' 81 f1 = QFile(self.non_existing_filename) 82 self.assertFalse(f1.exists()) 83 f2 = QFile(self.existing_filename) 84 self.assertTrue(f2.exists()) 85 86 87if __name__ == '__main__': 88 unittest.main() 89 90