Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_magics_parser_multiple_lines_command():
user_command = """hvacText = sc.textFile("path")
hvacSchema = StructType([StructField("date", StringType(), False),StructField("time", StringType(), False),StructField("targettemp", IntegerType(), False),StructField("actualtemp", IntegerType(), False),StructField("buildingID", StringType(), False)])
hvac = hvacText.map(lambda s: s.split(",")).filter(lambda s: s[0] != "Date").map(lambda s:(str(s[0]), str(s[1]), int(s[2]), int(s[3]), str(s[6]) ))
hvacdf = sqlContext.createDataFrame(hvac,hvacSchema)
hvacdf.registerTempTable("hvac")
data = sqlContext.sql("select buildingID, (targettemp - actualtemp) as temp_diff, date from hvac where date = \"6/1/13\"")
data"""
subcommand, force, output_var, command = parser.parse_user_command(user_command)
assert_equals("run", subcommand)
assert_equals(False, force)
assert output_var is None
assert_equals(user_command, command)
def custom_test(**vars):
print("I accept anything")
return
class MyValidator(pyblish.api.Validator):
def process(self, context):
assert False, "I won't stop the extractor"
class MyExtractor(pyblish.api.Extractor):
def process(self, context):
print("I came, I saw, I extracted..")
count["#"] += 1
pyblish.api.register_test(custom_test)
pyblish.util.publish(plugins=[MyValidator, MyExtractor])
assert_equals(count["#"], 1)
def test_url_change_updates_existing_redirects(self):
r = Redirect.objects.create(site_id=self.site_id, new_path='/nested-category/2008/1/10/first-article/', old_path='some-path')
self.publishable.slug = 'old-article-new-slug'
self.publishable.save()
tools.assert_equals(2, Redirect.objects.count())
r = Redirect.objects.get(pk=r.pk)
tools.assert_equals('some-path', r.old_path)
tools.assert_equals('/nested-category/2008/1/10/old-article-new-slug/', r.new_path)
tools.assert_equals(self.site_id, r.site_id)
return "data"
app = Flask(__name__)
api = flask_restful.Api(app, default_mediatype=None)
api.representations = {}
@api.representation('text/plain')
def text_rep(data, status_code, headers=None):
resp = app.make_response((str(data), status_code, headers))
return resp
api.add_resource(Foo, '/')
with app.test_client() as client:
res = client.get('/', headers=[('Accept', 'text/plain')])
assert_equals(res.status_code, 200)
assert_equals(res.content_type, 'text/plain')
assert_equals(result.tableId, 'syn2757980')
assert_equals(len(result.headers), 4)
rs = result.asRowSet()
assert_equals(len(rs.rows), 4)
result = TableQueryResult(synapse=MockSynapse(),
query="select State, min(Born), count(State), avg(Hipness) from syn2757980"
" group by Living")
df = result.asDataFrame()
assert_equals(df.shape, (4, 4))
assert_equals(list(df['State'].values), ['PA', 'MO', 'DC', 'NC'])
# check integer, double and boolean types after PLFM-3073 is fixed
assert_equals(list(df['MIN(Born)'].values), [1935, 1928, 1929, 1926],
"Unexpected values" + str(df['MIN(Born)'].values))
assert_equals(list(df['COUNT(State)'].values), [2, 3, 1, 1])
assert_equals(list(df['AVG(Hipness)'].values), [1.1, 2.38, 3.14, 4.38])
def test_get_labels_lut_empty_labels(self):
lut = du.get_labels_lut([], self.subset)
assert_is_instance(lut, np.ndarray)
assert_equals(lut.dtype, int)
assert_equals(lut.ndim, 1)
assert_equals(lut.shape, (1,))
assert_list_equal(lut.tolist(), [0])
def test_parse_db_connection_string(self):
url = 'mysql://wikimetrics:wikimetrics@localhost/wikimetrics'
user, password, host, dbName = parse_db_connection_string(url)
assert_equals(user, 'wikimetrics')
assert_equals(password, 'wikimetrics')
assert_equals(host, 'localhost')
assert_equals(dbName, 'wikimetrics')
def test_generate_picks_up_on_takedown(self):
self.publishable.publish_to = timezone.now() + timedelta(days=1)
self.publishable.save()
self._signal_clear()
generate_publish_signals(timezone.now() + timedelta(days=1, seconds=2))
tools.assert_equals(0, len(self.publish_received))
tools.assert_equals(1, len(self.unpublish_received))
tools.assert_equals(self.publishable, self.unpublish_received[0]['publishable'].target)
# Test with parameters eps=10 and min_pts=5
scan = ddbscan.DDBSCAN(10, 5)
for p in data:
scan.add_point(p, 1, "Desc")
scan.compute()
count_outliers = 0
for p in scan.points_data:
if p.cluster == -1:
count_outliers = count_outliers + p.count
count_clusters = len(scan.clusters)
assert_equals(count_outliers, 100)
assert_equals(count_clusters, 0)
def test_createNode():
"""cmdx.createNode works"""
node = cmdx.createNode("transform")
parent = cmdx.createNode("transform", name="MyNode")
assert_equals(parent.name(), "MyNode")
child = cmdx.createNode("transform", name="MyNode", parent=parent)
assert_equals(child, parent.child())
node = cmdx.createNode("transform", name="MyNode")
node = cmdx.createNode("transform", name="MyNode", parent=node)