'''Unit tests for lib.build.'''
from pathlib import Path
import sys
-if '' in sys.path: sys.path.remove('')
+if '' in sys.path:
+ sys.path.remove('')
sys.path.append(str(Path(__file__).parent.parent.parent.parent))
from os import getcwd, makedirs, walk
from os.path import basename
from shutil import rmtree
from unittest import TestCase
-from re import compile
+import re
from ya2.build.build import InsideDir, files, exec_cmd, _branch, _version, \
to_be_built
makedirs('test_get_files/a')
makedirs('test_get_files/b')
makedirs('test_get_files/c')
- with open('test_get_files/a/c.ext1', 'w') as ftest:
+ with open('test_get_files/a/c.ext1', 'w', encoding='utf8') as ftest:
ftest.write('0123456789')
- with open('test_get_files/a/d.ext2', 'w'): pass
- with open('test_get_files/b/e.ext2', 'w') as ftest:
+ with open('test_get_files/a/d.ext2', 'w', encoding='utf8'):
+ pass
+ with open('test_get_files/b/e.ext2', 'w', encoding='utf8') as ftest:
ftest.write('0123456789')
- with open('test_get_files/b/f.ext3', 'w'): pass
- with open('test_get_files/c/g.ext2', 'w'): pass
+ with open('test_get_files/b/f.ext3', 'w', encoding='utf8'):
+ pass
+ with open('test_get_files/c/g.ext2', 'w', encoding='utf8'):
+ pass
def tearDown(self):
rmtree('test_get_files')
patterns = [
"^0a[0-9]+$",
"^0rc[0-9]+$",
- "^0\.[0-9]+$"]
- compiled = [compile(pattern) for pattern in patterns]
+ r"^0\.[0-9]+$"]
+ compiled = [re.compile(pattern) for pattern in patterns]
matches = [pattern.match(_version()) for pattern in compiled]
self.assertTrue(any(matches))
def test_to_be_built(self):
tgt = 'test_get_files/tgt.txt'
- with open('test_get_files/src.txt', 'w') as fsrc:
+ with open('test_get_files/src.txt', 'w', encoding='utf8') as fsrc:
fsrc.write('src')
- with open(tgt, 'w') as ftgt:
+ with open(tgt, 'w', encoding='utf8') as ftgt:
ftgt.write('tgt')
self.assertTrue(to_be_built(tgt, ['test_get_files/src.txt']))