def init_config_file(): vhost_log = helper.read_file( '/etc/apache2/conf-available/other-vhosts-access-log.conf') security = helper.read_file('/etc/apache2/conf-available/security.conf') apache2_conf = helper.read_file('/etc/apache2/apache211.conf') apache2_conf_new = apache2_conf + security + vhost_log helper.write_file('/etc/apache2/apache211.conf', apache2_conf_new)
def fix(path): ck = 1 result = helper.read_file(path) obj = re.compile( r'LogFormat \"\%h \%l \%u \%t \\\"\%r\\\" \%>s \%b \\\"\%\{Referer\}i\\\" \\\"\%\{User-Agent\}i\\\"\" combined', re.MULTILINE).findall(result) if len(obj) == 0: add_logformat(path) obj1 = re.compile(r'CustomLog \$\{APACHE_LOG_DIR\}\/access\.log (.+)', re.MULTILINE).findall(result) if len(obj1) == 0: add_customlog(path) else: for i in obj1: if i != 'combined': ck = 0 break if ck == 0: add_customlog(path) result = helper.read_file(helper.sites_config) obj2 = re.compile(r'CustomLog \$\{APACHE_LOG_DIR\}\/access\.log (.+)', re.MULTILINE).findall(result) if len(obj2) == 0: add_customlog(helper.sites_config) else: for i in obj2: if i != 'combined': ck = 0 break if ck == 0: add_customlog(helper.sites_config)
def fix(path): a = list() result = helper.read_file(path) vtconf = re.findall(r'[^#]<VirtualHost (.*?)>(.*?)<\/VirtualHost>', result, re.DOTALL) for i in vtconf: a.append(i[0]) for i in a: vtconf = re.findall( r'[^#]<VirtualHost ' + i + r'>(.*?)<\/VirtualHost>', result, re.DOTALL) ssluse = re.findall(r'^\s*SSLUseStapling (.+)', vtconf[0], re.MULTILINE) ssltap = re.findall(r'^\s*SSLStaplingCache (.+)', vtconf[0], re.MULTILINE) if len(ssluse) == 0: add_directive(i, path, '\tSSLUseStapling On\n') if len(ssltap) == 0: add_directive( i, path, '\tSSLStaplingCache dc:UNIX:logs/ssl_staple_socket\n') result = helper.read_file(path) ssluse = re.findall(r'^\s*SSLUseStapling (.+)', result, re.MULTILINE) ssltap = re.findall(r'^\s*SSLStaplingCache (.+)', result, re.MULTILINE) for i in ssluse: if i != 'On' and i != 'on': fix_directory(path) break for i in ssltap: if i != 'dc:UNIX:logs/ssl_staple_socket': fix_directory(path) break
def fix(path): result = helper.read_file(path) obj = re.compile(r'^\s*LogLevel (.+)', re.MULTILINE).findall(result) if len(obj) > 1 or len(obj) == 0: add_LogLevel_config() else: if obj[0] != 'notice core:info': set_LogLevel_config(path) obj1 = re.compile(r'^\s*ErrorLog (.+)', re.MULTILINE).findall(result) if len(obj1) > 1 or len(obj1) == 0: add_ErrorLog_config(path) else: if obj1[0] != '${APACHE_LOG_DIR}/error.log': set_ErrorLog_config(path) result = helper.read_file(helper.envvars) obj2 = re.compile(r'^\s*export APACHE_LOG_DIR=(.+)', re.MULTILINE).findall(result) if len(obj2) > 1 or len(obj2) == 0: add_logdir_config() else: if obj2[0] != '/var/log/apache2$SUFFIX': add_logdir_config() result = helper.read_file(helper.sites_config) obj3 = re.compile(r'^\s*ErrorLog (.+)', re.MULTILINE).findall(result) if len(obj3) > 1 or len(obj3) == 0: add_ErrorLog_config(helper.sites_config) else: if obj3[0] != '${APACHE_LOG_DIR}/error.log': set_ErrorLog_config(helper.sites_config)
def fix(path): a = list() result = helper.read_file(path) vtconf = re.findall(r'[^#]<VirtualHost (.*?)>(.*?)<\/VirtualHost>', result, re.DOTALL) for i in vtconf: a.append(i[0]) for i in a: vtconf = re.findall( r'[^#]<VirtualHost ' + i + r'>(.*?)<\/VirtualHost>', result, re.DOTALL) sslhonor = re.findall(r'^\s*SSLHonorCipherOrder (.+)', vtconf[0], re.MULTILINE) sslcipher = re.findall(r'^\s*SSLCipherSuite (.+)', vtconf[0], re.MULTILINE) if len(sslhonor) == 0: add_directive(i, path, '\tSSLHonorCipherOrder On\n') if len(sslcipher) == 0: add_directive( i, path, '\tSSLCipherSuite ALL:!EXP:!NULL:!ADH:!LOW:!SSLv2:!SSLv3:!MD5:!RC4\n' ) result = helper.read_file(path) sslhonor = re.findall(r'^\s*SSLHonorCipherOrder (.+)', result, re.MULTILINE) sslcipher = re.findall(r'^\s*SSLCipherSuite (.+)', result, re.MULTILINE) for i in sslhonor: if i != 'On' and i != 'on': fix_directory(path) break for i in sslcipher: if i != 'ALL:!EXP:!NULL:!ADH:!LOW:!SSLv2:!SSLv3:!MD5:!RC4': fix_directory(path) break
def fix(path): f = os.popen('apache2ctl -M 2> /dev/null | grep rewrite') result = f.read()[:-1] f.close() if len(result) == 0: os.system('a2enmod rewrite > /dev/null') #os.system('service apache2 restart > /dev/null') result = helper.read_file(path) rewrite_e = re.compile(r'^\s*RewriteEngine (.*?)\n', re.MULTILINE).findall(result) if len(rewrite_e) == 0: replace = result + '\nRewriteEngine On\n' helper.write_file(path, replace) if len(rewrite_e) != 0: if rewrite_e[0] != 'On' and rewrite_e[0] != 'on': replace = re.sub(r'^\s*RewriteEngine (?:.*?)\n', 'RewriteEngine On\n', result, flags=re.MULTILINE) helper.write_file(path, replace) result = helper.read_file(path) if len( re.compile( r'RewriteCond %\{THE_REQUEST\} !HTTP\/1\\\.1\$\nRewriteRule \.\* - \[F\]\nRewriteOptions Inherit\n', re.DOTALL).findall(result)) == 0: replace = result + 'RewriteCond %{THE_REQUEST} !HTTP/1\.1$\nRewriteRule .* - [F]\nRewriteOptions Inherit\n' helper.write_file(path, replace)
def test_data(self): """Verify test data integrity. """ # Initial test data must differ from the "proofed" test data. self.assertNotEqual( read_file(REFERENCE_YW7), read_file(PROOFED_YW7))
def fix(path): result = helper.read_file(path) obj = re.findall( r'(^\s*Header always append X-Frame-Options SAMEORIGIN|Header always append X-Frame-Options DENY)', result, re.MULTILINE) if len(obj) == 0: result = helper.read_file(path) replace = result + 'Header always append X-Frame-Options SAMEORIGIN\n' helper.write_file(path, replace)
def check(path): # print '' # print ' Configure the Error Log '.center(85, '#') # print '' global check_num result = helper.read_file(path) obj = re.compile(r'^\s*LogLevel (.+)', re.MULTILINE).findall(result) if len(obj) != 0: for i in obj: if i != 'notice core:info': error_list.append('[WARNING] LogLevel directive value') check_num += 1 break else: error_list.append('[WARNING] LogLevel directive is not exist') check_num += 1 obj1 = re.compile(r'^\s*ErrorLog (.+)', re.MULTILINE).findall(result) if len(obj1) != 0: for i in obj1: if i != '${APACHE_LOG_DIR}/error.log': error_list.append( '[WARNING] ErrorLog directive in apache2 configuration') check_num += 1 break else: error_list.append('[WARNING] ErrorLog directive is not exist') check_num += 1 result = helper.read_file(helper.envvars) obj2 = re.compile(r'^\s*export APACHE_LOG_DIR=(.+)', re.MULTILINE).findall(result) if len(obj2) != 0: for i in obj2: if i != '/var/log/apache2$SUFFIX': error_list.append('[WARNING] APACHE_LOG_DIR configure') check_num += 1 break else: error_list.append('[WARNING] APACHE_LOG_DIR is not exist in envvars') check_num += 1 result = helper.read_file(helper.sites_config) obj3 = re.compile(r'^\s*ErrorLog (.+)', re.MULTILINE).findall(result) if len(obj3) != 0: for i in obj3: if i != '${APACHE_LOG_DIR}/error.log': error_list.append( '[WARNING] ErrorLog configure in virtual host') check_num += 1 break else: error_list.append( '[WARNING] ErrorLog directive is not exist in VirtualHost') check_num += 1 if check_num > 0: error_list.insert(0, 31) else: error_list.insert(0, 0) return error_list
def test_html_to_yw7_ui(self): """Use YwCnvUi class. """ copyfile(REFERENCE_HTML, TEST_HTML) converter = Yw7Converter() converter.run(TEST_HTML) self.assertEqual( converter.ui.infoHowText, 'ERROR: This document is not meant to be written back.') self.assertEqual(read_file(TEST_YW7), read_file(REFERENCE_YW7))
def test_html_to_yw7_ui(self): """Use YwCnvUi class. """ copyfile(REFERENCE_HTML, TEST_HTML) converter = Yw7Converter() converter.run(TEST_HTML) self.assertEqual( converter.ui.infoHowText, 'SUCCESS: "' + os.path.normpath(TEST_YW7) + '" written.') self.assertEqual(read_file(TEST_YW7), read_file(REFERENCE_YW7))
def add_ErrorLog_config(path): if path == helper.config_path: result = helper.read_file(path) result = re.sub(r'^\s*ErrorLog (.+)', '', result, flags=re.MULTILINE) replace = result + 'ErrorLog ${APACHE_LOG_DIR}/error.log\n' helper.write_file(path, replace) else: result = helper.read_file(path) result = re.sub(r'^\s*ErrorLog (.+)', '', result, flags=re.MULTILINE) result = re.sub(r'^\s*<\/VirtualHost>', '', result, flags=re.MULTILINE) replace = result + '\tErrorLog ${APACHE_LOG_DIR}/error.log\n</VirtualHost>\n' helper.write_file(path, replace)
def test_html_to_yw7(self): """Use YwCnv class. """ copyfile(REFERENCE_HTML, TEST_HTML) yw7File = Yw7File(TEST_YW7) documentFile = importClass(TEST_HTML) converter = YwCnv() self.assertEqual(converter.convert( documentFile, yw7File), 'SUCCESS: "' + os.path.normpath(TEST_YW7) + '" written.') self.assertEqual(read_file(TEST_YW7), read_file(REFERENCE_YW7))
def check(path): # print '' # print ' Configure the Access Log '.center(85, '#') # print '' global check_num ck = 1 result = helper.read_file(path) obj = re.compile( r'LogFormat \"\%h \%l \%u \%t \\\"\%r\\\" \%>s \%b \\\"\%\{Referer\}i\\\" \\\"\%\{User-Agent\}i\\\"\" combined', re.MULTILINE).findall(result) if len(obj) == 0: error_list.append( '[WARNING] LogFormat directive has recommended information is not exist' ) check_num += 1 obj1 = re.compile(r'CustomLog \$\{APACHE_LOG_DIR\}\/access\.log (.+)', re.MULTILINE).findall(result) if len(obj1) == 0: error_list.append( '[WARNING] CustomLog directive for access log is not exist') check_num += 1 else: for i in obj1: if i != 'combined': ck = 0 break if ck == 0: error_list.append( "[WARNING] CustomLog directive don't use combined format") check_num += 1 result = helper.read_file(helper.sites_config) obj2 = re.compile(r'CustomLog \$\{APACHE_LOG_DIR\}\/access\.log (.+)', re.MULTILINE).findall(result) if len(obj2) == 0: error_list.append( '[WARNING] CustomLog directive for access log is not exist in VirtualHost' ) check_num += 1 else: for i in obj2: if i != 'combined': ck = 0 break if ck == 0: error_list.append( "[WARNING] CustomLog directive don't use combined format in VirtualHost" ) check_num += 1 if check_num > 0: error_list.insert(0, 32) else: error_list.insert(0, 0) return error_list
def test_imp_to_yw7_ui(self): """Use YwCnvUi class. """ copyfile(PROOFED_IMP, TEST_IMP) converter = Yw7Converter() converter.run(TEST_IMP) self.assertEqual( converter.ui.infoHowText, 'SUCCESS: "' + os.path.normpath(TEST_YW7) + '" written.') self.assertEqual(read_file(TEST_YW7), read_file(PROOFED_YW7)) self.assertEqual(read_file(TEST_YW7_BAK), read_file(REFERENCE_YW7))
def install_apparmor(): os.system( 'apt-get install apparmor > /home/anhthc/do_an/log_apparmor1 2> /home/anhthc/do_an/log_apparmor2' ) result = helper.read_file('/home/anhthc/do_an/log_apparmor2') if len(result) == 0: print 'Install AppArmor done!' os.system( 'apt-get install libapache2-mod-apparmor > /home/anhthc/do_an/log_apparmor3 2> /home/anhthc/do_an/log_apparmor4' ) result = helper.read_file('/home/anhthc/do_an/log_apparmor4') if len(result) == 0: print 'Install libapache2-mod-apparmor done!' os.system('/etc/init.d/apparmor start > /dev/null')
def open_file(self): helper.reset_values() file = open("../../output/output.txt", "w").close() self.out_text.clear() name = QtGui.QFileDialog.getOpenFileName(QtGui.QFileDialog(), "Open File") self.make_ui() if name: file = open(name, 'r') helper.read_file(name) with file: text = file.read() self.code_text.setText(text) else: print("invalid file")
def test_yw7_to_exp_ui(self): """Use YwCnvUi class. """ converter = Yw7Converter() kwargs = {'suffix': exportClass.SUFFIX} converter.run(TEST_YW7, **kwargs) self.assertEqual(converter.ui.infoHowText, 'SUCCESS: "' + os.path.normpath(TEST_EXP) + '" written.') with zipfile.ZipFile(TEST_EXP, 'r') as myzip: myzip.extract(ODF_CONTENT, EXEC_PATH) myzip.close self.assertEqual(read_file(EXEC_PATH + ODF_CONTENT), read_file(DATA_PATH + ODF_CONTENT))
def test_yw7_to_exp(self): """Use YwCnv class. """ yw7File = Yw7File(TEST_YW7) documentFile = exportClass(TEST_EXP) converter = YwCnv() self.assertEqual(converter.convert( yw7File, documentFile), 'SUCCESS: "' + os.path.normpath(TEST_EXP) + '" written.') with zipfile.ZipFile(TEST_EXP, 'r') as myzip: myzip.extract(ODF_CONTENT, EXEC_PATH) myzip.close self.assertEqual(read_file(EXEC_PATH + ODF_CONTENT), read_file(DATA_PATH + ODF_CONTENT))
def test_material(tetrahedron_eps10, tetrahedron_eps10_material_function, tetrahedron_eps10_material_file): with open(tetrahedron_eps10["byXi"], "r") as out_file: datas = read_file(out_file) with open(tetrahedron_eps10_material_function["byXi"], "r") as out_file: datas_func = read_file(out_file) with open(tetrahedron_eps10_material_file["byXi"], "r") as out_file: datas_file = read_file(out_file) xi = 6.0 for zz in (0.1, 1.0, 10.0): cp_pot = [data[5] for data in datas if (data[2] == zz and data[3] == xi)][0] cp_pot_func = [data[5] for data in datas_func if (data[2] == zz and data[3] == xi)][0] cp_pot_file = [data[5] for data in datas_file if (data[2] == zz and data[3] == xi)][0] assert_rel_tol(cp_pot, cp_pot_func, reltol=0.01) assert_rel_tol(cp_pot, cp_pot_file, reltol=0.01)
def check(): # print '' # print ' Deny IP Address Based Requests '.center(85, '#') # print '' global check_num f = os.popen('apache2ctl -M 2> /dev/null | grep rewrite') result = f.read()[:-1] f.close() if len(result) == 0: error_list.append('[WARNING] Rewrite module is disable') check_num += 1 else: result = helper.read_file(helper.config_path) rewrite_e = re.compile(r'^\s*RewriteEngine (.*?)\n',re.MULTILINE).findall(result) if len(rewrite_e) == 0 or (rewrite_e[0] != 'On' and rewrite_e[0] != 'on'): error_list.append('[WARNING] RewriteEngine is not enable') check_num += 1 if len(re.compile(r'RewriteCond %\{HTTP_HOST\} !\^www\\\.example\\\.com \[NC\]\nRewriteCond %\{REQUEST_URI\} !\^\/error \[NC\]\nRewriteRule \^\.\(\.\*\) - \[L,F\]\n',re.DOTALL).findall(result)) == 0: error_list.append('[WARNING] Not configure rewrite to disallows request that disallows IP based requests by requiring a HTTP HOST header') check_num += 1 if check_num > 0: error_list.insert(0, 28) else: error_list.insert(0, 0) return error_list
def fix_directive(path): result = helper.read_file(path) replace = re.sub(r'^\s*MaxKeepAliveRequests .+', 'MaxKeepAliveRequests 100\n', result, flags=re.MULTILINE) helper.write_file(path, replace)
def fix_directive(path): result = helper.read_file(path) replace = re.sub(r'^\s*SSLProtocol\s+.+', '\t\tSSLProtocol TLSv1.1 TLS1.2', result, flags=re.MULTILINE) helper.write_file(path, replace)
def set_directive(path): result = helper.read_file(path) replace = re.sub(r'^\s*ServerSignature (?:.+)', 'ServerSignature Off\n', result, flags=re.MULTILINE) helper.write_file(path, replace)
def fix_directive(path): result = helper.read_file(path) replace = re.sub(r'^\s*LimitRequestline .+', 'LimitRequestline 512', result, flags=re.MULTILINE) helper.write_file(path, replace)
def check(): # print '' # print ' Restrict Listen Directive '.center(85, '#') # print '' global check_num result = helper.read_file('/etc/apache2/ports.conf') obj = re.compile(r'^\s*Listen (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\d+', re.MULTILINE).findall(result) obj1 = re.compile(r'^\s*Listen (.+)', re.MULTILINE).findall(result) for i in obj: if i == '0.0.0.0': error_list.append('[WARNING] Detect IP address of all zeros') check_num += 1 if len(obj) != len(obj1): error_list.append( '[WARNING] Detect listen directive with no IP address specified') check_num += 1 if check_num > 0: error_list.insert(0, 29) else: error_list.insert(0, 0) # print '[NOTICE] A Listen directive with no IP address specified, or with an IP address of all zeros should not be used' error_list.append('[NOTICE] Khong ho tro fix tu dong') return error_list
def check(path): # print '' # print ' Enable OCSP Stapling '.center(85, '#') # print '' global check_num result = helper.read_file(path) vtconf = re.findall(r'[^#]<VirtualHost (.*?)>(.*?)<\/VirtualHost>', result, re.DOTALL) ssltap = re.findall(r'^\s*SSLStaplingCache (.+)', result, re.MULTILINE) ssluse = re.findall(r'^\s*SSLUseStapling (.+)', result, re.MULTILINE) if len(vtconf) != len(ssltap) or len(vtconf) != len(ssluse): error_list.append( '[WARNING] SSLStaplingCache or SSLUseStapling is not exsit in some VirtualHost' ) check_num += 1 for i in ssluse: if i != 'on' and i != 'On': error_list.append('[WARNING] Config SSLUseStapling') check_num += 1 break for i in ssltap: if i != 'shmcb:logs/ssl_staple_cache(512000)' and i != 'dbm:logs/ssl_staple_cache.db' and i != 'dc:UNIX:logs/ssl_staple_socket': error_list.append('[WARNING] Config SSLStaplingCache') check_num += 1 break if check_num > 0: error_list.insert(0, 42) else: error_list.insert(0, 0) return error_list
def fix_directive(path): result = helper.read_file(path) replace = re.sub(r'^\s*KeepAlive .+', 'KeepAlive On\n', result, flags=re.MULTILINE) helper.write_file(path, replace)
def fix(path): result = helper.read_file(path) replace = re.sub(r'^\s*SSLInsecureRenegotiation .+', 'SSLInsecureRenegotiation off\n', result, flags=re.MULTILINE) helper.write_file(path, replace)
def check(path): # print '' # print ' Restrict Access to .ht* files '.center(85, '#') # print '' global check_num result = helper.read_file(path) obj = re.compile(r'[^#]<FilesMatch "\^\\\.ht">(.*?[^#])<\/FilesMatch>', re.DOTALL).findall(result) if len(obj) == 0: error_list.append( '[WARNING] FilesMatch directive is not present in the apache configuration' ) check_num += 1 else: if obj[0][1:-1] != 'Require all denied': error_list.append( '[WARNING] FilesMatch directive is not config to restrict access to any file .ht*' ) check_num += 1 if check_num > 0: error_list.insert(0, 26) else: error_list.insert(0, 0) return error_list
def check(path): # print '' # print ' Set Timeout Limits for Request Headers and Body'.center(85, '#') # print '' global check_num f = os.popen("apache2ctl -M 2> /dev/null | grep reqtimeout ") result = f.read() f.close() if len(result) == 0: error_list.append('[WARNING] mod_requesttimeout disable') check_num += 1 result = helper.read_file(path) obj = re.findall(r'^\s*RequestReadTimeout (.+)',result,re.MULTILINE) if len(obj) == 0: error_list.append('[WARNING] RequestReadTimeout directive is not exsit') check_num += 1 else: if obj[0] != 'header=20-40,MinRate=500 body=20,MinRate=500': error_list.append('[WARNING] RequestReadTimeout value') check_num += 1 if check_num > 0: error_list.insert(0, 50) else: error_list.insert(0, 0) return error_list
def test_clean(self): tmp = helper.get_tmpfile_path('formats.mscx') mscxyz.execute(['clean', tmp]) cleaned = helper.read_file(tmp) self.assertFalse('<font' in cleaned) self.assertFalse('<b>' in cleaned) self.assertFalse('<i>' in cleaned) self.assertFalse('<pos' in cleaned) self.assertFalse('<LayoutBreak>' in cleaned) self.assertFalse('<StemDirection>' in cleaned)
def test_infinite_plate_xi0(pecplate_fast): with open(pecplate_fast["byXi"], "r") as out_file: datas = read_file(out_file) for xx, yy, zz, xi, polarize, cp_pot in datas: if xi == 1.0e-6: assert_rel_tol(polarize, 3.186000e+02) if zz == 0.1: assert_rel_tol(cp_pot, -7.418665e-01) elif zz == 1.0: assert_rel_tol(cp_pot, -7.418665e-04) elif zz == 10.0: assert_rel_tol(cp_pot, -7.418665e-07)
def test_infinite_plate_xi6(pecplate_fast): with open(pecplate_fast["byXi"], "r") as out_file: datas = read_file(out_file) for xx, yy, zz, xi, polarize, cp_pot in datas: if xi == 6.0: assert_rel_tol(polarize, 2.074813e+02) if zz == 0.1: assert_rel_tol(cp_pot, -4.249017e-01) elif zz == 1.0: assert_rel_tol(cp_pot, -2.523156e-07) elif zz == 10.0: assert_rel_tol(cp_pot, -2.712012e-55)
def test_set(self): meta, tree, tmp = self._init_class('simple.mscx') meta.workTitle = 'WT' meta.movement_title = 'MT' tree.save() tree = XMLTree(tmp) meta = MetaTag(tree.xml_root) self.assertEqual(meta.work_title, 'WT') self.assertEqual(meta.movementTitle, 'MT') xml_string = helper.read_file(tmp) self.assertTrue('<metaTag name="workTitle">WT</metaTag>' in xml_string)
def _assert_set(self, filename): tmp = helper.get_tmpfile_path(filename) tree = XMLTree(tmp) vbox = Vbox(tree.xml_root) vbox.Title = 'lol' vbox.composer = 'lol' tree.save() tree = XMLTree(tmp) vbox = Vbox(tree.xml_root) self.assertEqual(vbox.title, 'lol') self.assertEqual(vbox.Composer, 'lol') xml_string = helper.read_file(tmp) self.assertTrue('<text>lol</text>' in xml_string)
def test_tetrahedron_eps10_xi6(tetrahedron_eps10): with open(tetrahedron_eps10["byXi"], "r") as out_file: datas = read_file(out_file) for xx, yy, zz, xi, polarize, cp_pot in datas: if xi == 6.0: assert_rel_tol(polarize, 2.074813e+02) if zz == 0.1: assert_rel_tol(cp_pot, -7.722056e-02) elif zz == 1.0: assert_rel_tol(cp_pot, -3.197261e-09) elif zz == 10.0: assert_rel_tol(cp_pot, -3.089228e-58) else: raise ValueError("TEST: no comparison value for zz={zz:e}, xi={xi:e}".format(zz=zz, xi=xi))
def test_tetrahedron_pec_xi6(tetrahedron_pec): with open(tetrahedron_pec["byXi"], "r") as out_file: datas = read_file(out_file) for xx, yy, zz, xi, polarize, cp_pot in datas: if xi == 6.0: assert_rel_tol(polarize, 2.074813e+02) if zz == 0.1: assert_rel_tol(cp_pot, -1.168001e-01) elif zz == 1.0: assert_rel_tol(cp_pot, -6.200486e-09) elif zz == 10.0: assert_rel_tol(cp_pot, -6.149101e-58) else: raise ValueError("TEST: no comparison value for zz={zz:e}, xi={xi:e}".format(zz=zz, xi=xi))
def test_tetrahedron_pec_xi0(tetrahedron_pec): with open(tetrahedron_pec["byXi"], "r") as out_file: datas = read_file(out_file) for xx, yy, zz, xi, polarize, cp_pot in datas: if xi == 1.0e-6: assert_rel_tol(polarize, 3.186000e+02) if zz == 0.1: assert_rel_tol(cp_pot, -2.029004e-01) elif zz == 1.0: assert_rel_tol(cp_pot, -2.493534e-06) elif zz == 10.0: assert_rel_tol(cp_pot, -3.243498e-12) else: raise ValueError("TEST: no comparison value for zz={zz:e}, xi={xi:e}".format(zz=zz, xi=xi))
def test_coin_xi6(coin): with open(coin["byXi"], "r") as out_file: datas = read_file(out_file) for xx, yy, zz, xi, polarize, cp_pot in datas: if xi == 6.0: assert_rel_tol(polarize, 2.074813e+02) if zz == 0.1: assert_rel_tol(cp_pot, -3.599895e-01) elif zz == 1.0: assert_rel_tol(cp_pot, -1.923850e-07) elif zz == 10.0: assert_rel_tol(cp_pot, -3.601550e-56) else: raise ValueError("TEST: no comparison value for zz={zz:e}, xi={xi:e}".format(zz=zz, xi=xi))
def test_coin_xi0(coin): with open(coin["byXi"], "r") as out_file: datas = read_file(out_file) for xx, yy, zz, xi, polarize, cp_pot in datas: if xi == 1.0e-6: assert_rel_tol(polarize, 3.186000e+02) if zz == 0.1: assert_rel_tol(cp_pot, -6.313080e-01) elif zz == 1.0: assert_rel_tol(cp_pot, -1.248351e-04) elif zz == 10.0: assert_rel_tol(cp_pot, -2.273920e-10) else: raise ValueError("TEST: no comparison value for zz={zz:e}, xi={xi:e}".format(zz=zz, xi=xi))
def test_method_save_new_name(self): tmp = helper.get_tmpfile_path('simple.mscx') tree = XMLTree(tmp) tree.save(new_name=tmp) result = helper.read_file(tmp) self.assertTrue('<metaTag name="arranger"></metaTag>' in result)
def test_thinplate2nm(thinplate2nm): with open(thinplate2nm["out"], "r") as out_file: datas = read_file(out_file) validate_long_short_range(datas)
def test_clean_add_style(self): tmp = helper.get_tmpfile_path('simple.mscx') mscxyz.execute(['clean', '--style', helper.get_tmpfile_path('style.mss'), tmp]) style = helper.read_file(tmp) self.assertTrue('<staffUpperBorder>77</staffUpperBorder>' in style)
def test_pecplate(pecplate_validate): with open(pecplate_validate["out"], "r") as out_file: datas = read_file(out_file) validate_long_short_range(datas)
def test_init(self): vbox, tree, tmp = self._init_class('no-vbox.mscx') tree.save() xml_string = helper.read_file(tmp) self.assertTrue('<VBox>' in xml_string)